Mercurial > vim
annotate src/typval.c @ 23909:5db7d275543c v8.2.2497
patch 8.2.2497: no error when using more than one character for a register
Commit: https://github.com/vim/vim/commit/418a29f0ffcaa0a3d778724ab6d1111db525d3cc
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Feb 10 22:23:41 2021 +0100
patch 8.2.2497: no error when using more than one character for a register
Problem: No error when using more than one character for a register name.
Solution: In Vim9 script check for a single character string. (closes https://github.com/vim/vim/issues/7814)
Fix that VAR_BOOL and VAR_SPECIAL are not considered equal.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 10 Feb 2021 22:30:06 +0100 |
parents | d12ef361d9de |
children | 083f07f99e20 |
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 |
21851
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
172 static varnumber_T |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
173 tv_get_bool_or_number_chk(typval_T *varp, int *denote, int want_bool) |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 varnumber_T n = 0L; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
176 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 switch (varp->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 case VAR_NUMBER: |
22405
0ef3ae4ec70e
patch 8.2.1751: using 2 where bool is expected may throw an error
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
180 if (in_vim9script() && want_bool && varp->vval.v_number != 0 |
21913
9fc27a955f00
patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents:
21861
diff
changeset
|
181 && varp->vval.v_number != 1) |
9fc27a955f00
patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents:
21861
diff
changeset
|
182 { |
9fc27a955f00
patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents:
21861
diff
changeset
|
183 semsg(_(e_using_number_as_bool_nr), varp->vval.v_number); |
9fc27a955f00
patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents:
21861
diff
changeset
|
184 break; |
9fc27a955f00
patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents:
21861
diff
changeset
|
185 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 return varp->vval.v_number; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 case VAR_FLOAT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 #ifdef FEAT_FLOAT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
189 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
|
190 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
193 case VAR_PARTIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
194 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
|
195 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
196 case VAR_STRING: |
21831
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21425
diff
changeset
|
197 if (in_vim9script()) |
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21425
diff
changeset
|
198 { |
22860
53acb89ec9f2
patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents:
22405
diff
changeset
|
199 emsg_using_string_as(varp, !want_bool); |
21831
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21425
diff
changeset
|
200 break; |
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21425
diff
changeset
|
201 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
202 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
|
203 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
|
204 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
|
205 return n; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 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
|
208 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 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
|
211 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
213 case VAR_SPECIAL: |
21851
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
214 if (!want_bool && in_vim9script()) |
21831
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21425
diff
changeset
|
215 { |
22930
84567584951f
patch 8.2.2012: Vim9: confusing error message when using bool wrongly
Bram Moolenaar <Bram@vim.org>
parents:
22860
diff
changeset
|
216 if (varp->v_type == VAR_BOOL) |
84567584951f
patch 8.2.2012: Vim9: confusing error message when using bool wrongly
Bram Moolenaar <Bram@vim.org>
parents:
22860
diff
changeset
|
217 emsg(_(e_using_bool_as_number)); |
84567584951f
patch 8.2.2012: Vim9: confusing error message when using bool wrongly
Bram Moolenaar <Bram@vim.org>
parents:
22860
diff
changeset
|
218 else |
84567584951f
patch 8.2.2012: Vim9: confusing error message when using bool wrongly
Bram Moolenaar <Bram@vim.org>
parents:
22860
diff
changeset
|
219 emsg(_("E611: Using a Special as a Number")); |
21831
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21425
diff
changeset
|
220 break; |
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21425
diff
changeset
|
221 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 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
|
223 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 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
|
226 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
228 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
230 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
|
231 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
232 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
233 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
234 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
|
235 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
237 case VAR_ANY: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
238 case VAR_VOID: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
239 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
|
240 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
241 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 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
|
243 n = -1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
244 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
245 *denote = TRUE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
246 return n; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 |
21851
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
249 /* |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
250 * Get the number value of a variable. |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
251 * If it is a String variable, uses vim_str2nr(). |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
252 * For incompatible types, return 0. |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
253 * tv_get_number_chk() is similar to tv_get_number(), but informs the |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
254 * caller of incompatible types: it sets *denote to TRUE if "denote" |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
255 * is not NULL or returns -1 otherwise. |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
256 */ |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
257 varnumber_T |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
258 tv_get_number(typval_T *varp) |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
259 { |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
260 int error = FALSE; |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
261 |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
262 return tv_get_number_chk(varp, &error); // return 0L on error |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
263 } |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
264 |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
265 varnumber_T |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
266 tv_get_number_chk(typval_T *varp, int *denote) |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
267 { |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
268 return tv_get_bool_or_number_chk(varp, denote, FALSE); |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
269 } |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
270 |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
271 /* |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
272 * Get the boolean value of "varp". This is like tv_get_number_chk(), |
21913
9fc27a955f00
patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents:
21861
diff
changeset
|
273 * but in Vim9 script accepts Number (0 and 1) and Bool/Special. |
21851
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
274 */ |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
275 varnumber_T |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
276 tv_get_bool(typval_T *varp) |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
277 { |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
278 return tv_get_bool_or_number_chk(varp, NULL, TRUE); |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
279 } |
727820154b1a
patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents:
21831
diff
changeset
|
280 |
21861
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
281 /* |
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
282 * Get the boolean value of "varp". This is like tv_get_number_chk(), |
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
283 * but in Vim9 script accepts Number and Bool. |
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
284 */ |
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
285 varnumber_T |
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
286 tv_get_bool_chk(typval_T *varp, int *denote) |
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
287 { |
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
288 return tv_get_bool_or_number_chk(varp, denote, TRUE); |
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
289 } |
cd8dafe937ba
patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents:
21851
diff
changeset
|
290 |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
291 #ifdef FEAT_FLOAT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
292 float_T |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
293 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
|
294 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
295 switch (varp->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
296 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
297 case VAR_NUMBER: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
298 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
|
299 case VAR_FLOAT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
300 return varp->vval.v_float; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
301 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
302 case VAR_PARTIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
303 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
|
304 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
305 case VAR_STRING: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
306 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
|
307 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
308 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
309 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
|
310 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
311 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
312 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
|
313 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
314 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
315 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
|
316 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
317 case VAR_SPECIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
318 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
|
319 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
320 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
321 # ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
322 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
|
323 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
324 # endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
325 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
326 # ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
327 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
|
328 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
329 # endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
330 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
331 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
|
332 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
333 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
334 case VAR_ANY: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
335 case VAR_VOID: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
336 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
|
337 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
338 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
339 return 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
340 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
341 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
342 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
343 /* |
23175
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
344 * Give an error and return FAIL unless "tv" is a string. |
23142
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
345 */ |
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
346 int |
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
347 check_for_string(typval_T *tv) |
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
348 { |
23175
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
349 if (tv->v_type != VAR_STRING) |
23142
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
350 { |
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
351 emsg(_(e_stringreq)); |
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
352 return FAIL; |
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
353 } |
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
354 return OK; |
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
355 } |
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
356 |
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22930
diff
changeset
|
357 /* |
23175
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
358 * Give an error and return FAIL unless "tv" is a non-empty string. |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
359 */ |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
360 int |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
361 check_for_nonempty_string(typval_T *tv) |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
362 { |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
363 if (check_for_string(tv) == FAIL) |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
364 return FAIL; |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
365 if (tv->vval.v_string == NULL || *tv->vval.v_string == NUL) |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
366 { |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
367 emsg(_(e_non_empty_string_required)); |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
368 return FAIL; |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
369 } |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
370 return OK; |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
371 } |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
372 |
d7294a6220ac
patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents:
23142
diff
changeset
|
373 /* |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 * 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
|
375 * 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
|
376 * 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
|
377 * 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
|
378 * 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
|
379 * Never returns NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 * 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
|
381 * NULL on error. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
382 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
383 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
384 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
|
385 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
386 static char_u mybuf[NUMBUFLEN]; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
387 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
388 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
|
389 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
390 |
23786
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
391 /* |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
392 * Like tv_get_string() but don't allow number to string conversion for Vim9. |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
393 */ |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
394 char_u * |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
395 tv_get_string_strict(typval_T *varp) |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
396 { |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
397 static char_u mybuf[NUMBUFLEN]; |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
398 char_u *res = tv_get_string_buf_chk_strict( |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
399 varp, mybuf, in_vim9script()); |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
400 |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
401 return res != NULL ? res : (char_u *)""; |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
402 } |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
403 |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
404 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
405 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
|
406 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
407 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
|
408 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 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
|
410 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 * 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
|
414 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 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
|
417 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
418 static char_u mybuf[NUMBUFLEN]; |
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 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
|
421 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 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
|
425 { |
23786
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
426 return tv_get_string_buf_chk_strict(varp, buf, FALSE); |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
427 } |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
428 |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
429 char_u * |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
430 tv_get_string_buf_chk_strict(typval_T *varp, char_u *buf, int strict) |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
431 { |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 switch (varp->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
433 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
434 case VAR_NUMBER: |
23786
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
435 if (strict) |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
436 { |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
437 emsg(_(e_using_number_as_string)); |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
438 break; |
0512923e54e1
patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents:
23563
diff
changeset
|
439 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 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
|
441 (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
|
442 return buf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
444 case VAR_PARTIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
445 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
|
446 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 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
|
449 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 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
|
452 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
453 case VAR_FLOAT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 #ifdef FEAT_FLOAT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
455 emsg(_(e_float_as_string)); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
457 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
458 case VAR_STRING: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
459 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
|
460 return varp->vval.v_string; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
461 return (char_u *)""; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
462 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
463 case VAR_SPECIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
464 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
|
465 return buf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
467 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
|
468 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
470 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
472 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
|
473 char *status; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
474 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
475 if (job == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
476 return (char_u *)"no process"; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
477 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
|
478 : 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
|
479 : "run"; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
480 # ifdef UNIX |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
481 vim_snprintf((char *)buf, NUMBUFLEN, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
482 "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
|
483 # elif defined(MSWIN) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 vim_snprintf((char *)buf, NUMBUFLEN, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 "process %ld %s", |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
486 (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
|
487 status); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 # else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
489 // fall-back |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
490 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
|
491 # endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
492 return buf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 #endif |
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_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 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
|
500 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
|
501 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 if (channel == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 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
|
504 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
505 vim_snprintf((char *)buf, NUMBUFLEN, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
506 "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
|
507 return buf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
508 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
509 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
511 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
512 case VAR_ANY: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
513 case VAR_VOID: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
514 emsg(_(e_inval_string)); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
515 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 return NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
518 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 |
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 * 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
|
522 * string() on Dict, List, etc. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
523 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 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
|
526 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
527 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
|
528 || varp->v_type == VAR_DICT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
529 || varp->v_type == VAR_BLOB |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
530 || varp->v_type == VAR_FUNC |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
531 || varp->v_type == VAR_PARTIAL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
532 || varp->v_type == VAR_FLOAT) |
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 typval_T tmp; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
535 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 f_string(varp, &tmp); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
537 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
|
538 clear_tv(varp); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
539 *varp = tmp; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
540 return tmp.vval.v_string; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
541 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
542 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
|
543 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
544 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
545 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
546 * 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
|
547 * 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
|
548 * TRUE. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
549 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
550 int |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
551 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
|
552 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
553 int lock = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
554 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
555 switch (tv->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
556 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
557 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
558 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
|
559 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
|
560 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
561 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 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
|
563 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
|
564 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
566 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
|
567 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
|
568 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
569 default: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
570 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 } |
22298
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22043
diff
changeset
|
572 return value_check_lock(tv->v_lock, name, use_gettext) |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22043
diff
changeset
|
573 || (lock != 0 && value_check_lock(lock, name, use_gettext)); |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
574 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
575 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
576 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
577 * 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
|
578 * 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
|
579 * 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
|
580 * 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
|
581 * make a copy later. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
582 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
583 void |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
584 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
|
585 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
586 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
|
587 to->v_lock = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
588 switch (from->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
589 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
590 case VAR_NUMBER: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
591 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
592 case VAR_SPECIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
593 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
|
594 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
595 case VAR_FLOAT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
596 #ifdef FEAT_FLOAT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
597 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
|
598 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
599 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
600 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
601 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
602 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
|
603 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
|
604 ++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
|
605 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
606 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
607 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
608 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
609 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
|
610 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
|
611 ++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
|
612 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
613 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
614 case VAR_STRING: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
615 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
616 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
|
617 to->vval.v_string = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
618 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
619 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
620 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
|
621 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
|
622 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
|
623 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
624 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
625 case VAR_PARTIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
626 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
|
627 to->vval.v_partial = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
628 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
629 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
630 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
|
631 ++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
|
632 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
633 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
634 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
635 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
|
636 to->vval.v_blob = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
637 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
638 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
639 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
|
640 ++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
|
641 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
642 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
644 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
|
645 to->vval.v_list = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
646 else |
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 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
|
649 ++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
|
650 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
651 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
652 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
653 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
|
654 to->vval.v_dict = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
655 else |
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 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
|
658 ++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
|
659 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
660 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
661 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
662 case VAR_ANY: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
663 case VAR_VOID: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
664 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
|
665 break; |
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 } |
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 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
670 * 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
|
671 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
672 int |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
673 typval_compare( |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
674 typval_T *typ1, // first operand |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
675 typval_T *typ2, // second operand |
23553
5c094273c015
patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents:
23519
diff
changeset
|
676 exprtype_T type, // operator |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
677 int ic) // ignore case |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
678 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
679 int i; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
680 varnumber_T n1, n2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
681 char_u *s1, *s2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
682 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
|
683 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
|
684 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
685 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
|
686 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
687 // 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
|
688 // it means TRUE. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
689 n1 = (type == EXPR_ISNOT); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
690 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
691 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
|
692 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
693 if (type_is) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
694 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
695 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
|
696 && 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
|
697 if (type == EXPR_ISNOT) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
698 n1 = !n1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
699 } |
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 != typ2->v_type |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
701 || (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
|
702 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
703 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
|
704 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
|
705 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
706 emsg(_(e_invalblob)); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
707 clear_tv(typ1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
708 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
709 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
710 else |
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 // 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
|
713 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
|
714 if (type == EXPR_NEQUAL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
715 n1 = !n1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
716 } |
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 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
|
719 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
720 if (type_is) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
721 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
722 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
|
723 && 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
|
724 if (type == EXPR_ISNOT) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
725 n1 = !n1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
726 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
727 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
|
728 || (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
|
729 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
730 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
|
731 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
|
732 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
733 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
|
734 clear_tv(typ1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
735 return FAIL; |
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 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
738 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
739 // 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
|
740 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
|
741 ic, FALSE); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
742 if (type == EXPR_NEQUAL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
743 n1 = !n1; |
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 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
746 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
747 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
|
748 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
749 if (type_is) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
750 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
751 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
|
752 && 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
|
753 if (type == EXPR_ISNOT) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
754 n1 = !n1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
755 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 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
|
757 || (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
|
758 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
759 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
|
760 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
|
761 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
762 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
|
763 clear_tv(typ1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
764 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
765 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
766 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
767 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
768 // 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
|
769 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
|
770 ic, FALSE); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
771 if (type == EXPR_NEQUAL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
772 n1 = !n1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
773 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
774 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
775 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
776 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
|
777 || 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
|
778 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
779 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
|
780 && 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
|
781 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
782 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
|
783 clear_tv(typ1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
784 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
785 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
786 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
|
787 && typ1->vval.v_partial == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
788 || (typ2->v_type == VAR_PARTIAL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
789 && typ2->vval.v_partial == NULL)) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
790 // 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
|
791 // Otherwise they are not equal. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
792 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
|
793 else if (type_is) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
794 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
795 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
|
796 // 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
|
797 // the same |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
798 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
|
799 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
|
800 && typ2->v_type == VAR_PARTIAL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
801 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
|
802 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
803 n1 = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
804 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
805 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
806 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
|
807 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
|
808 n1 = !n1; |
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 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
811 #ifdef FEAT_FLOAT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
812 // 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
|
813 // 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
|
814 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
|
815 && 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
|
816 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
817 float_T f1, f2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
818 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
819 f1 = tv_get_float(typ1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
820 f2 = tv_get_float(typ2); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
821 n1 = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
822 switch (type) |
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 case EXPR_IS: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
825 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
|
826 case EXPR_ISNOT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
827 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
|
828 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
|
829 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
|
830 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
|
831 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
|
832 case EXPR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
833 case EXPR_MATCH: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
834 default: break; // avoid gcc warning |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
835 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
836 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
837 #endif |
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 // 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
|
840 // 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
|
841 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
|
842 && 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
|
843 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
844 n1 = tv_get_number(typ1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
845 n2 = tv_get_number(typ2); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
846 switch (type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
847 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
848 case EXPR_IS: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
849 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
|
850 case EXPR_ISNOT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
851 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
|
852 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
|
853 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
|
854 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
|
855 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
|
856 case EXPR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
857 case EXPR_MATCH: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
858 default: break; // avoid gcc warning |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
859 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
860 } |
23555
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
861 else if (in_vim9script() && (typ1->v_type == VAR_BOOL |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
862 || typ2->v_type == VAR_BOOL)) |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
863 { |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
864 if (typ1->v_type != typ2->v_type) |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
865 { |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
866 semsg(_(e_cannot_compare_str_with_str), |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
867 vartype_name(typ1->v_type), vartype_name(typ2->v_type)); |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
868 clear_tv(typ1); |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
869 return FAIL; |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
870 } |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
871 n1 = typ1->vval.v_number; |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
872 n2 = typ2->vval.v_number; |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
873 switch (type) |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
874 { |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
875 case EXPR_IS: |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
876 case EXPR_EQUAL: n1 = (n1 == n2); break; |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
877 case EXPR_ISNOT: |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
878 case EXPR_NEQUAL: n1 = (n1 != n2); break; |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
879 default: |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
880 emsg(_(e_invalid_operation_for_bool)); |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
881 clear_tv(typ1); |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
882 return FAIL; |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
883 } |
0f7bb6f706f0
patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
884 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
885 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
886 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
887 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
|
888 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
|
889 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
|
890 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
|
891 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
892 i = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
893 n1 = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
894 switch (type) |
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 case EXPR_IS: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
897 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
|
898 case EXPR_ISNOT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
899 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
|
900 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
|
901 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
|
902 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
|
903 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
|
904 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
905 case EXPR_MATCH: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
906 case EXPR_NOMATCH: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
907 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
|
908 if (type == EXPR_NOMATCH) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
909 n1 = !n1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
910 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
911 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
912 default: break; // avoid gcc warning |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
913 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
914 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
915 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
|
916 if (in_vim9script()) |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
917 { |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
918 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
|
919 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
|
920 } |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
921 else |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
922 { |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
923 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
|
924 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
|
925 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
926 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
927 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
928 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
929 |
23788
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
930 /* |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
931 * Convert any type to a string, never give an error. |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
932 * When "quotes" is TRUE add quotes to a string. |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
933 * Returns an allocated string. |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
934 */ |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
935 char_u * |
23788
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
936 typval_tostring(typval_T *arg, int quotes) |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
937 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
938 char_u *tofree; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
939 char_u numbuf[NUMBUFLEN]; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
940 char_u *ret = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
941 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
942 if (arg == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
943 return vim_strsave((char_u *)"(does not exist)"); |
23788
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
944 if (!quotes && arg->v_type == VAR_STRING) |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
945 { |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
946 ret = vim_strsave(arg->vval.v_string == NULL ? (char_u *)"" |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
947 : arg->vval.v_string); |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
948 } |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
949 else |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
950 { |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
951 ret = tv2string(arg, &tofree, numbuf, 0); |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
952 // Make a copy if we have a value but it's not in allocated memory. |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
953 if (ret != NULL && tofree == NULL) |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
954 ret = vim_strsave(ret); |
d12ef361d9de
patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents:
23786
diff
changeset
|
955 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
956 return ret; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
957 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
958 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
959 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
960 * 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
|
961 * 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
|
962 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
963 int |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
964 tv_islocked(typval_T *tv) |
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 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
|
967 || (tv->v_type == VAR_LIST |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
968 && tv->vval.v_list != NULL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 && (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
|
970 || (tv->v_type == VAR_DICT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
971 && tv->vval.v_dict != NULL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
972 && (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
|
973 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
974 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
975 static int |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
976 func_equal( |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
977 typval_T *tv1, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
978 typval_T *tv2, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
979 int ic) // ignore case |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
980 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 char_u *s1, *s2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
982 dict_T *d1, *d2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
983 int a1, a2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
984 int i; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
985 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
986 // 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
|
987 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
|
988 : 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
|
989 if (s1 != NULL && *s1 == NUL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 s1 = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 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
|
992 : 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
|
993 if (s2 != NULL && *s2 == NUL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 s2 = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 if (s1 == NULL || s2 == NULL) |
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 if (s1 != s2) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
998 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
999 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1000 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
|
1001 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1002 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1003 // 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
|
1004 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
|
1005 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
|
1006 if (d1 == NULL || d2 == NULL) |
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 if (d1 != d2) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 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
|
1012 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1014 // 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
|
1015 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
|
1016 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
|
1017 if (a1 != a2) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 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
|
1020 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
|
1021 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
|
1022 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1024 return TRUE; |
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 |
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 * 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
|
1029 * 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
|
1030 * 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
|
1031 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 int |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 tv_equal( |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 typval_T *tv1, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1035 typval_T *tv2, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 int ic, // ignore case |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 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
|
1038 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1039 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
|
1040 char_u *s1, *s2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1041 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
|
1042 int r; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1043 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
|
1044 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1045 // 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
|
1046 // 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
|
1047 // 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
|
1048 // 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
|
1049 // 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
|
1050 // recursiveness quickly. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 if (!recursive) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1052 tv_equal_recurse_limit = 1000; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 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
|
1054 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 --tv_equal_recurse_limit; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 return TRUE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 // 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
|
1060 // arguments. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1061 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
|
1062 || (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
|
1063 && (tv2->v_type == VAR_FUNC |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 || (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
|
1065 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 ++recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 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
|
1068 --recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 return r; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1070 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1071 |
23909
5db7d275543c
patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents:
23788
diff
changeset
|
1072 if (tv1->v_type != tv2->v_type |
5db7d275543c
patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents:
23788
diff
changeset
|
1073 && ((tv1->v_type != VAR_BOOL && tv1->v_type != VAR_SPECIAL) |
5db7d275543c
patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents:
23788
diff
changeset
|
1074 || (tv2->v_type != VAR_BOOL && tv2->v_type != VAR_SPECIAL))) |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1076 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1077 switch (tv1->v_type) |
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 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1080 ++recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1081 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
|
1082 --recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1083 return r; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1084 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1085 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1086 ++recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1087 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
|
1088 --recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1089 return r; |
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 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1092 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
|
1093 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 case VAR_NUMBER: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1096 case VAR_SPECIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 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
|
1098 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1099 case VAR_STRING: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1100 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
|
1101 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
|
1102 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
|
1103 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1104 case VAR_FLOAT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1105 #ifdef FEAT_FLOAT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1106 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
|
1107 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1108 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1109 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 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
|
1111 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1112 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1113 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1114 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
|
1115 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1116 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1117 case VAR_PARTIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1118 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
|
1119 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1120 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1121 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
|
1122 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1123 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1124 case VAR_ANY: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 case VAR_VOID: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1126 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 } |
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 // 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
|
1130 // 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
|
1131 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1132 } |
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 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1135 * Get an option value. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1136 * "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
|
1137 * "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
|
1138 * Return OK or FAIL. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1139 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1140 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
|
1141 eval_option( |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1142 char_u **arg, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1143 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
|
1144 int evaluate) |
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 char_u *option_end; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1147 long numval; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1148 char_u *stringval; |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1149 getoption_T opt_type; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1150 int c; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1151 int working = (**arg == '+'); // has("+option") |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1152 int ret = OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 int opt_flags; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1154 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1155 // 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
|
1156 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
|
1157 if (option_end == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1159 if (rettv != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1160 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
|
1161 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1162 } |
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 if (!evaluate) |
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 *arg = option_end; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1168 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1169 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1170 c = *option_end; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1171 *option_end = NUL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1172 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
|
1173 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
|
1174 |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1175 if (opt_type == gov_unknown) |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1176 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1177 if (rettv != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1178 semsg(_(e_unknown_option), *arg); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1179 ret = FAIL; |
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 else if (rettv != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1182 { |
23519
cb66613dd9d5
patch 8.2.2302: Vim9: using an option value may use uninitialized memory
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
1183 rettv->v_lock = 0; |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1184 if (opt_type == gov_hidden_string) |
20587
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 rettv->v_type = VAR_STRING; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1187 rettv->vval.v_string = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1188 } |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1189 else if (opt_type == gov_hidden_bool || opt_type == gov_hidden_number) |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1190 { |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1191 rettv->v_type = in_vim9script() && opt_type == gov_hidden_bool |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1192 ? VAR_BOOL : VAR_NUMBER; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1193 rettv->vval.v_number = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1194 } |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1195 else if (opt_type == gov_bool || opt_type == gov_number) |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1196 { |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1197 if (in_vim9script() && opt_type == gov_bool) |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1198 { |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1199 rettv->v_type = VAR_BOOL; |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1200 rettv->vval.v_number = numval ? VVAL_TRUE : VVAL_FALSE; |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1201 } |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1202 else |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1203 { |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1204 rettv->v_type = VAR_NUMBER; |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1205 rettv->vval.v_number = numval; |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1206 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1207 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1208 else // string option |
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 rettv->v_type = VAR_STRING; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1211 rettv->vval.v_string = stringval; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1212 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1213 } |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1214 else if (working && (opt_type == gov_hidden_bool |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1215 || opt_type == gov_hidden_number |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23276
diff
changeset
|
1216 || opt_type == gov_hidden_string)) |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1217 ret = FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1218 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1219 *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
|
1220 *arg = option_end; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1221 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1222 return ret; |
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 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1226 * 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
|
1227 * Return OK or FAIL. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1229 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
|
1230 eval_number( |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1231 char_u **arg, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1232 typval_T *rettv, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1233 int evaluate, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1234 int want_string UNUSED) |
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 int len; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1237 #ifdef FEAT_FLOAT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 char_u *p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 int get_float = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1240 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1241 // 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
|
1242 // "[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
|
1243 // 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
|
1244 // 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
|
1245 // omitted. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1246 // 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
|
1247 // ":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
|
1248 if (**arg == '.') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1249 p = *arg; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1250 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1251 p = skipdigits(*arg + 1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1252 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
|
1253 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1254 get_float = TRUE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1255 p = skipdigits(p + 2); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1256 if (*p == 'e' || *p == 'E') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1257 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1258 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1259 if (*p == '-' || *p == '+') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1260 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1261 if (!vim_isdigit(*p)) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1262 get_float = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1263 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1264 p = skipdigits(p + 1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1265 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1266 if (ASCII_ISALPHA(*p) || *p == '.') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1267 get_float = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1268 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1269 if (get_float) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1270 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1271 float_T f; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1272 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1273 *arg += string2float(*arg, &f); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1274 if (evaluate) |
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 rettv->v_type = VAR_FLOAT; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1277 rettv->vval.v_float = f; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1278 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1279 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1280 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1281 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1282 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
|
1283 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1284 char_u *bp; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1285 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
|
1286 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1287 // Blob constant: 0z0123456789abcdef |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1288 if (evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1289 blob = blob_alloc(); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1290 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
|
1291 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1292 if (!vim_isxdigit(bp[1])) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1293 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1294 if (blob != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1295 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1296 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
|
1297 ga_clear(&blob->bv_ga); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1298 VIM_CLEAR(blob); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1299 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1300 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1301 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1302 if (blob != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1303 ga_append(&blob->bv_ga, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1304 (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
|
1305 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
|
1306 ++bp; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1307 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1308 if (blob != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1309 rettv_blob_set(rettv, blob); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1310 *arg = bp; |
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 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1313 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1314 varnumber_T n; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1315 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1316 // decimal, hex or octal number |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1317 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
|
1318 ? STR2NR_NO_OCT + STR2NR_QUOTE |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1319 : 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
|
1320 if (len == 0) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1321 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1322 semsg(_(e_invexpr2), *arg); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1323 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1324 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1325 *arg += len; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1326 if (evaluate) |
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 rettv->v_type = VAR_NUMBER; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1329 rettv->vval.v_number = n; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1330 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1331 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1332 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1333 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1334 |
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 * 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
|
1337 * Return OK or FAIL. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1338 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1339 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
|
1340 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
|
1341 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1342 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
|
1343 char_u *end; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1344 int extra = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1345 int len; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1346 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1347 // 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
|
1348 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
|
1349 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1350 if (*p == '\\' && p[1] != NUL) |
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 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1353 // 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
|
1354 // 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
|
1355 // reserve space for 18 extra. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1356 // 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
|
1357 if (*p == '<') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1358 extra += 18; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1359 } |
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 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1362 if (*p != '"') |
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 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
|
1365 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1366 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1367 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1368 // 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
|
1369 if (!evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1370 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1371 *arg = p + 1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1372 return OK; |
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 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1375 // 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
|
1376 // characters. |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1377 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
|
1378 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
|
1379 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
|
1380 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
|
1381 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
|
1382 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
|
1383 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1384 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
|
1385 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1386 if (*p == '\\') |
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 switch (*++p) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1389 { |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1390 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
|
1391 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
|
1392 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
|
1393 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
|
1394 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
|
1395 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
|
1396 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1397 case 'X': // hex: "\x1", "\x12" |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1398 case 'x': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1399 case 'u': // Unicode: "\u0023" |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1400 case 'U': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1401 if (vim_isxdigit(p[1])) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1402 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1403 int n, nr; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1404 int c = toupper(*p); |
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 if (c == 'X') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1407 n = 2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1408 else if (*p == 'u') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1409 n = 4; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1410 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1411 n = 8; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1412 nr = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1413 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
|
1414 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1415 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1416 nr = (nr << 4) + hex2nr(*p); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1417 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1418 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1419 // 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
|
1420 // 'encoding'. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1421 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
|
1422 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
|
1423 else |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1424 *end++ = nr; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1425 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1426 break; |
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 // octal: "\1", "\12", "\123" |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1429 case '0': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1430 case '1': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1431 case '2': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1432 case '3': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1433 case '4': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1434 case '5': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1435 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
|
1436 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
|
1437 if (*p >= '0' && *p <= '7') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1438 { |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1439 *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
|
1440 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
|
1441 *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
|
1442 } |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1443 ++end; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1444 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1445 |
20627
8bce783af0cb
patch 8.2.0867: using {xxx} for encoding a modifier is not nice
Bram Moolenaar <Bram@vim.org>
parents:
20603
diff
changeset
|
1446 // 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
|
1447 case '<': |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1448 { |
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
|
1449 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
|
1450 |
20627
8bce783af0cb
patch 8.2.0867: using {xxx} for encoding a modifier is not nice
Bram Moolenaar <Bram@vim.org>
parents:
20603
diff
changeset
|
1451 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
|
1452 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
|
1453 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
|
1454 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
|
1455 { |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1456 end += extra; |
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1457 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
|
1458 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
|
1459 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
|
1460 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1461 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1462 // FALLTHROUGH |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1463 |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1464 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
|
1465 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1466 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1467 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1468 else |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1469 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
|
1470 } |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1471 *end = NUL; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1472 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
|
1473 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1474 *arg = p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1475 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1476 return OK; |
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 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1480 * 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
|
1481 * Return OK or FAIL. |
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 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
|
1484 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
|
1485 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1486 char_u *p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1487 char_u *str; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1488 int reduce = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1489 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1490 // 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
|
1491 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
|
1492 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1493 if (*p == '\'') |
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 if (p[1] != '\'') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1496 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1497 ++reduce; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1498 ++p; |
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 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1501 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1502 if (*p != '\'') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1503 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1504 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
|
1505 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1506 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1507 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1508 // 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
|
1509 if (!evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1510 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1511 *arg = p + 1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1512 return OK; |
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 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1515 // 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
|
1516 str = alloc((p - *arg) - reduce); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1517 if (str == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1518 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1519 rettv->v_type = VAR_STRING; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1520 rettv->vval.v_string = str; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1521 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1522 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
|
1523 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1524 if (*p == '\'') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1525 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1526 if (p[1] != '\'') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1527 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1528 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1529 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1530 MB_COPY_CHAR(p, str); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1531 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1532 *str = NUL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1533 *arg = p + 1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1534 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1535 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1536 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1537 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1538 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1539 * 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
|
1540 * 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
|
1541 * "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
|
1542 * 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
|
1543 * May return NULL. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1544 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1545 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1546 tv2string( |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1547 typval_T *tv, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1548 char_u **tofree, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1549 char_u *numbuf, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1550 int copyID) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1551 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1552 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
|
1553 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1554 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1555 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1556 * 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
|
1557 * "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
|
1558 * 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
|
1559 * 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
|
1560 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1561 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
|
1562 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
|
1563 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1564 char_u *string = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1565 int len; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1566 int cc; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1567 char_u *name; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1568 int mustfree = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1569 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1570 ++*arg; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1571 name = *arg; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1572 len = get_env_len(arg); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1573 if (evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1574 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1575 if (len == 0) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1576 return FAIL; // invalid empty name |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1577 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1578 cc = name[len]; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1579 name[len] = NUL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1580 // 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
|
1581 string = vim_getenv(name, &mustfree); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1582 if (string != NULL && *string != NUL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1583 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1584 if (!mustfree) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1585 string = vim_strsave(string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1586 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1587 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1588 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1589 if (mustfree) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1590 vim_free(string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1591 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1592 // 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
|
1593 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
|
1594 if (string != NULL && *string == '$') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1595 VIM_CLEAR(string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1596 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1597 name[len] = cc; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1598 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1599 rettv->v_type = VAR_STRING; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1600 rettv->vval.v_string = string; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1601 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1602 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1603 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1604 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1605 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1606 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1607 * 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
|
1608 * 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
|
1609 * Returns -1 on error. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1610 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1611 linenr_T |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1612 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
|
1613 { |
23276
b79cdad3ea2e
patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents:
23175
diff
changeset
|
1614 linenr_T lnum = -1; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1615 |
21831
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21425
diff
changeset
|
1616 if (argvars[0].v_type != VAR_STRING || !in_vim9script()) |
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21425
diff
changeset
|
1617 lnum = (linenr_T)tv_get_number_chk(&argvars[0], NULL); |
23276
b79cdad3ea2e
patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents:
23175
diff
changeset
|
1618 if (lnum <= 0) // no valid number, try using arg like line() |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1619 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1620 int fnum; |
23563
87671ccc6c6b
patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents:
23555
diff
changeset
|
1621 pos_T *fp = var2fpos(&argvars[0], TRUE, &fnum, FALSE); |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1622 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1623 if (fp != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1624 lnum = fp->lnum; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1625 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1626 return lnum; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1627 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1628 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1629 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1630 * 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
|
1631 * 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
|
1632 * Returns 0 on error. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1633 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1634 linenr_T |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1635 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
|
1636 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1637 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
|
1638 && 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
|
1639 && 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
|
1640 && buf != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1641 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
|
1642 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
|
1643 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1644 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1645 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1646 * 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
|
1647 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1648 buf_T * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1649 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
|
1650 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1651 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
|
1652 buf_T *buf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1653 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1654 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
|
1655 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
|
1656 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
|
1657 return NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1658 if (name == NULL || *name == NUL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1659 return curbuf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1660 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
|
1661 return lastbuf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1662 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1663 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
|
1664 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1665 // 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
|
1666 if (buf == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1667 buf = find_buffer(tv); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1668 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1669 return buf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1670 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1671 |
22025
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1672 /* |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1673 * Like tv_get_buf() but give an error message is the type is wrong. |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1674 */ |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1675 buf_T * |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1676 tv_get_buf_from_arg(typval_T *tv) |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1677 { |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1678 buf_T *buf; |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1679 |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1680 ++emsg_off; |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1681 buf = tv_get_buf(tv, FALSE); |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1682 --emsg_off; |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1683 if (buf == NULL |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1684 && tv->v_type != VAR_NUMBER |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1685 && tv->v_type != VAR_STRING) |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1686 // issue errmsg for type error |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1687 (void)tv_get_number(tv); |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1688 return buf; |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1689 } |
71f886a48ef5
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents:
21913
diff
changeset
|
1690 |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1691 #endif // FEAT_EVAL |