Mercurial > vim
comparison src/eval.c @ 137:3e7d17e425b0 v7.0044
updated for version 7.0044
author | vimboss |
---|---|
date | Tue, 25 Jan 2005 22:26:29 +0000 |
parents | f455396f3c3f |
children | 0ef5b70c3eaf |
comparison
equal
deleted
inserted
replaced
136:18f29039b83c | 137:3e7d17e425b0 |
---|---|
28 # include <fcntl.h> | 28 # include <fcntl.h> |
29 #endif | 29 #endif |
30 | 30 |
31 #if defined(FEAT_EVAL) || defined(PROTO) | 31 #if defined(FEAT_EVAL) || defined(PROTO) |
32 | 32 |
33 #if SIZEOF_INT <= 3 /* use long if int is smaller than 32 bits */ | 33 #define DICT_MAXNEST 100 /* maximum nesting of lists and dicts */ |
34 typedef long varnumber_T; | 34 |
35 #else | 35 /* |
36 typedef int varnumber_T; | 36 * In a hashtab item "hi_key" points to "di_key" in a dictitem. |
37 #endif | 37 * This avoids adding a pointer to the hashtab item. |
38 | |
39 /* | |
40 * Structure to hold an internal variable without a name. | |
41 */ | |
42 typedef struct | |
43 { | |
44 char v_type; /* see below: VAR_NUMBER, VAR_STRING, etc. */ | |
45 union | |
46 { | |
47 varnumber_T v_number; /* number value */ | |
48 char_u *v_string; /* string value (can be NULL!) */ | |
49 struct listvar_S *v_list; /* list value (can be NULL!) */ | |
50 struct dictvar_S *v_dict; /* dict value (can be NULL!) */ | |
51 } vval; | |
52 } typeval; | |
53 | |
54 /* Values for "v_type". */ | |
55 #define VAR_UNKNOWN 0 | |
56 #define VAR_NUMBER 1 /* "v_number" is used */ | |
57 #define VAR_STRING 2 /* "v_string" is used */ | |
58 #define VAR_FUNC 3 /* "v_string" is function name */ | |
59 #define VAR_LIST 4 /* "v_list" is used */ | |
60 #define VAR_DICT 5 /* "v_dict" is used */ | |
61 | |
62 /* | |
63 * Structure to hold an internal variable with a name. | |
64 * The "tv" must come first, so that this can be used as a "typeval" as well. | |
65 */ | |
66 typedef struct | |
67 { | |
68 typeval tv; /* type and value of the variable */ | |
69 char_u v_name[1]; /* name of variable (actually longer) */ | |
70 } var; | |
71 | |
72 typedef var * VAR; | |
73 | |
74 /* | |
75 * In a hashtable item "hi_key" points to "v_name" in a variable. | |
76 * This avoids adding a pointer to the hashtable item. | |
77 * VAR2HIKEY() converts a var pointer to a hashitem key pointer. | |
78 * HIKEY2VAR() converts a hashitem key pointer to a var pointer. | |
79 * HI2VAR() converts a hashitem pointer to a var pointer. | |
80 */ | |
81 static var dumvar; | |
82 #define VAR2HIKEY(v) ((v)->v_name) | |
83 #define HIKEY2VAR(p) ((VAR)(p - (dumvar.v_name - (char_u *)&dumvar.tv))) | |
84 #define HI2VAR(hi) HIKEY2VAR((hi)->hi_key) | |
85 | |
86 /* | |
87 * Structure to hold an item of a list: an internal variable without a name. | |
88 */ | |
89 struct listitem_S | |
90 { | |
91 struct listitem_S *li_next; /* next item in list */ | |
92 struct listitem_S *li_prev; /* previous item in list */ | |
93 typeval li_tv; /* type and value of the variable */ | |
94 }; | |
95 | |
96 typedef struct listitem_S listitem; | |
97 | |
98 /* | |
99 * Struct used by those that are using an item in a list. | |
100 */ | |
101 typedef struct listwatch_S | |
102 { | |
103 listitem *lw_item; /* item being watched */ | |
104 struct listwatch_S *lw_next; /* next watcher */ | |
105 } listwatch; | |
106 | |
107 /* | |
108 * Structure to hold info about a list. | |
109 */ | |
110 struct listvar_S | |
111 { | |
112 int lv_refcount; /* reference count */ | |
113 listitem *lv_first; /* first item, NULL if none */ | |
114 listitem *lv_last; /* last item, NULL if none */ | |
115 listwatch *lv_watch; /* first watcher, NULL if none */ | |
116 }; | |
117 | |
118 typedef struct listvar_S listvar; | |
119 | |
120 #define VAR_MAXNEST 100 /* maximum nesting of lists and dicts */ | |
121 | |
122 /* | |
123 * Structure to hold an item of a Dictionary. | |
124 * The key is copied into "di_key" to avoid an extra alloc/free for it. | |
125 */ | |
126 struct dictitem_S | |
127 { | |
128 typeval di_tv; /* type and value of the variable */ | |
129 char_u di_key[1]; /* key (actually longer!) */ | |
130 }; | |
131 | |
132 typedef struct dictitem_S dictitem; | |
133 | |
134 /* | |
135 * In a hashtable item "hi_key" points to "di_key" in a dictitem. | |
136 * This avoids adding a pointer to the hashtable item. | |
137 * DI2HIKEY() converts a dictitem pointer to a hashitem key pointer. | 38 * DI2HIKEY() converts a dictitem pointer to a hashitem key pointer. |
138 * HIKEY2DI() converts a hashitem key pointer to a dictitem pointer. | 39 * HIKEY2DI() converts a hashitem key pointer to a dictitem pointer. |
139 * HI2DI() converts a hashitem pointer to a dictitem pointer. | 40 * HI2DI() converts a hashitem pointer to a dictitem pointer. |
140 */ | 41 */ |
141 static dictitem dumdi; | 42 static dictitem_T dumdi; |
142 #define DI2HIKEY(di) ((di)->di_key) | 43 #define DI2HIKEY(di) ((di)->di_key) |
143 #define HIKEY2DI(p) ((dictitem *)(p - (dumdi.di_key - (char_u *)&dumdi.di_tv))) | 44 #define HIKEY2DI(p) ((dictitem_T *)(p - (dumdi.di_key - (char_u *)&dumdi))) |
144 #define HI2DI(hi) HIKEY2DI((hi)->hi_key) | 45 #define HI2DI(hi) HIKEY2DI((hi)->hi_key) |
145 | |
146 /* | |
147 * Structure to hold info about a Dictionary. | |
148 */ | |
149 struct dictvar_S | |
150 { | |
151 int dv_refcount; /* reference count */ | |
152 hashtable dv_hashtable; /* hashtable that refers to the items */ | |
153 }; | |
154 | |
155 typedef struct dictvar_S dictvar; | |
156 | 46 |
157 /* | 47 /* |
158 * Structure returned by get_lval() and used by set_var_lval(). | 48 * Structure returned by get_lval() and used by set_var_lval(). |
159 * For a plain name: | 49 * For a plain name: |
160 * "name" points to the variable name. | 50 * "name" points to the variable name. |
176 * "tv" points to the dict item value | 66 * "tv" points to the dict item value |
177 * "newkey" is NULL | 67 * "newkey" is NULL |
178 * For a non-existing Dict item: | 68 * For a non-existing Dict item: |
179 * "name" points to the (expanded) variable name. | 69 * "name" points to the (expanded) variable name. |
180 * "exp_name" NULL or non-NULL, to be freed later. | 70 * "exp_name" NULL or non-NULL, to be freed later. |
181 * "tv" points to the Dictionary typeval | 71 * "tv" points to the Dictionary typval_T |
182 * "newkey" is the key for the new item. | 72 * "newkey" is the key for the new item. |
183 */ | 73 */ |
184 typedef struct lval_S | 74 typedef struct lval_S |
185 { | 75 { |
186 char_u *ll_name; /* start of variable name (can be NULL) */ | 76 char_u *ll_name; /* start of variable name (can be NULL) */ |
187 char_u *ll_exp_name; /* NULL or expanded name in allocated memory. */ | 77 char_u *ll_exp_name; /* NULL or expanded name in allocated memory. */ |
188 typeval *ll_tv; /* Typeval of item being used. If "newkey" | 78 typval_T *ll_tv; /* Typeval of item being used. If "newkey" |
189 isn't NULL it's the Dict to which to add | 79 isn't NULL it's the Dict to which to add |
190 the item. */ | 80 the item. */ |
191 listitem *ll_li; /* The list item or NULL. */ | 81 listitem_T *ll_li; /* The list item or NULL. */ |
192 listvar *ll_list; /* The list or NULL. */ | 82 list_T *ll_list; /* The list or NULL. */ |
193 int ll_range; /* TRUE when a [i:j] range was used */ | 83 int ll_range; /* TRUE when a [i:j] range was used */ |
194 long ll_n1; /* First index for list */ | 84 long ll_n1; /* First index for list */ |
195 long ll_n2; /* Second index for list range */ | 85 long ll_n2; /* Second index for list range */ |
196 int ll_empty2; /* Second index is empty: [i:] */ | 86 int ll_empty2; /* Second index is empty: [i:] */ |
197 dictvar *ll_dict; /* The Dictionary or NULL */ | 87 dict_T *ll_dict; /* The Dictionary or NULL */ |
198 dictitem *ll_di; /* The dictitem or NULL */ | 88 dictitem_T *ll_di; /* The dictitem or NULL */ |
199 char_u *ll_newkey; /* New key for Dict in alloc. mem or NULL. */ | 89 char_u *ll_newkey; /* New key for Dict in alloc. mem or NULL. */ |
200 } lval; | 90 } lval_T; |
201 | 91 |
202 | 92 |
203 static char *e_letunexp = N_("E18: Unexpected characters in :let"); | 93 static char *e_letunexp = N_("E18: Unexpected characters in :let"); |
204 static char *e_listidx = N_("E684: list index out of range: %ld"); | 94 static char *e_listidx = N_("E684: list index out of range: %ld"); |
205 static char *e_undefvar = N_("E121: Undefined variable: %s"); | 95 static char *e_undefvar = N_("E121: Undefined variable: %s"); |
216 static char *e_funcref = N_("E718: Funcref required"); | 106 static char *e_funcref = N_("E718: Funcref required"); |
217 static char *e_dictrange = N_("E719: Cannot use [:] with a Dictionary"); | 107 static char *e_dictrange = N_("E719: Cannot use [:] with a Dictionary"); |
218 static char *e_letwrong = N_("E734: Wrong variable type for %s="); | 108 static char *e_letwrong = N_("E734: Wrong variable type for %s="); |
219 | 109 |
220 /* | 110 /* |
221 * All user-defined global variables are stored in "variables". | 111 * All user-defined global variables are stored in dictionary "globvardict". |
222 */ | 112 * "globvars_var" is the variable that is used for "g:". |
223 hashtable variables; | 113 */ |
224 | 114 static dict_T globvardict; |
225 /* | 115 static dictitem_T globvars_var; |
226 * Array to hold the hashtable with variables local to each sourced script. | 116 #define globvarht globvardict.dv_hashtab |
227 */ | 117 |
228 static garray_T ga_scripts = {0, 0, sizeof(hashtable), 4, NULL}; | 118 /* |
229 #define SCRIPT_VARS(id) (((hashtable *)ga_scripts.ga_data)[(id) - 1]) | 119 * Array to hold the hashtab with variables local to each sourced script. |
120 * Each item holds a variable (nameless) that points to the dict_T. | |
121 */ | |
122 typedef struct | |
123 { | |
124 dictitem_T sv_var; | |
125 dict_T sv_dict; | |
126 } scriptvar_T; | |
127 | |
128 static garray_T ga_scripts = {0, 0, sizeof(scriptvar_T), 4, NULL}; | |
129 #define SCRIPT_SV(id) (((scriptvar_T *)ga_scripts.ga_data)[(id) - 1]) | |
130 #define SCRIPT_VARS(id) (SCRIPT_SV(id).sv_dict.dv_hashtab) | |
230 | 131 |
231 static int echo_attr = 0; /* attributes used for ":echo" */ | 132 static int echo_attr = 0; /* attributes used for ":echo" */ |
232 | 133 |
233 /* Values for trans_function_name() argument: */ | 134 /* Values for trans_function_name() argument: */ |
234 #define TFN_INT 1 /* internal function name OK */ | 135 #define TFN_INT 1 /* internal function name OK */ |
266 ufunc_T *firstfunc = NULL; | 167 ufunc_T *firstfunc = NULL; |
267 | 168 |
268 #define FUNCARG(fp, j) ((char_u **)(fp->args.ga_data))[j] | 169 #define FUNCARG(fp, j) ((char_u **)(fp->args.ga_data))[j] |
269 #define FUNCLINE(fp, j) ((char_u **)(fp->lines.ga_data))[j] | 170 #define FUNCLINE(fp, j) ((char_u **)(fp->lines.ga_data))[j] |
270 | 171 |
172 #define MAX_FUNC_ARGS 20 /* maximum number of function arguments */ | |
173 #define VAR_SHORT_LEN 20 /* short variable name length */ | |
174 #define FIXVAR_CNT 12 /* number of fixed variables */ | |
175 | |
271 /* structure to hold info for a function that is currently being executed. */ | 176 /* structure to hold info for a function that is currently being executed. */ |
272 struct funccall | 177 typedef struct funccall_S |
273 { | 178 { |
274 ufunc_T *func; /* function being called */ | 179 ufunc_T *func; /* function being called */ |
275 int linenr; /* next line to be executed */ | 180 int linenr; /* next line to be executed */ |
276 int returned; /* ":return" used */ | 181 int returned; /* ":return" used */ |
277 int argcount; /* nr of arguments */ | 182 struct /* fixed variables for arguments */ |
278 typeval *argvars; /* arguments */ | 183 { |
279 var a0_var; /* "a:0" variable */ | 184 dictitem_T var; /* variable (without room for name) */ |
280 var firstline; /* "a:firstline" variable */ | 185 char_u room[VAR_SHORT_LEN]; /* room for the name */ |
281 var lastline; /* "a:lastline" variable */ | 186 } fixvar[FIXVAR_CNT]; |
282 hashtable l_vars; /* local function variables */ | 187 dict_T l_vars; /* l: local function variables */ |
283 typeval *rettv; /* return value */ | 188 dictitem_T l_vars_var; /* variable for l: scope */ |
189 dict_T l_avars; /* a: argument variables */ | |
190 dictitem_T l_avars_var; /* variable for a: scope */ | |
191 list_T l_varlist; /* list for a:000 */ | |
192 listitem_T l_listitems[MAX_FUNC_ARGS]; /* listitems for a:000 */ | |
193 typval_T *rettv; /* return value */ | |
284 linenr_T breakpoint; /* next line with breakpoint or zero */ | 194 linenr_T breakpoint; /* next line with breakpoint or zero */ |
285 int dbg_tick; /* debug_tick when breakpoint was set */ | 195 int dbg_tick; /* debug_tick when breakpoint was set */ |
286 int level; /* top nesting level of executed function */ | 196 int level; /* top nesting level of executed function */ |
287 }; | 197 } funccall_T; |
288 | 198 |
289 /* | 199 /* |
290 * Info used by a ":for" loop. | 200 * Info used by a ":for" loop. |
291 */ | 201 */ |
292 typedef struct forinfo_S | 202 typedef struct |
293 { | 203 { |
294 int fi_semicolon; /* TRUE if ending in '; var]' */ | 204 int fi_semicolon; /* TRUE if ending in '; var]' */ |
295 int fi_varcount; /* nr of variables in the list */ | 205 int fi_varcount; /* nr of variables in the list */ |
296 listwatch fi_lw; /* keep an eye on the item used. */ | 206 listwatch_T fi_lw; /* keep an eye on the item used. */ |
297 listvar *fi_list; /* list being used */ | 207 list_T *fi_list; /* list being used */ |
298 } forinfo; | 208 } forinfo_T; |
299 | 209 |
300 /* | 210 /* |
301 * Struct used by trans_function_name() | 211 * Struct used by trans_function_name() |
302 */ | 212 */ |
303 typedef struct | 213 typedef struct |
304 { | 214 { |
305 dictvar *fd_dict; /* Dictionary used */ | 215 dict_T *fd_dict; /* Dictionary used */ |
306 char_u *fd_newkey; /* new key in "dict" */ | 216 char_u *fd_newkey; /* new key in "dict" */ |
307 dictitem *fd_di; /* Dictionary item used */ | 217 dictitem_T *fd_di; /* Dictionary item used */ |
308 } funcdict; | 218 } funcdict_T; |
309 | |
310 | |
311 /* | |
312 * Initialize the global variables. | |
313 */ | |
314 void | |
315 eval_init() | |
316 { | |
317 hash_init(&variables); | |
318 } | |
319 | |
320 /* | |
321 * Return the name of the executed function. | |
322 */ | |
323 char_u * | |
324 func_name(cookie) | |
325 void *cookie; | |
326 { | |
327 return ((struct funccall *)cookie)->func->name; | |
328 } | |
329 | |
330 /* | |
331 * Return the address holding the next breakpoint line for a funccall cookie. | |
332 */ | |
333 linenr_T * | |
334 func_breakpoint(cookie) | |
335 void *cookie; | |
336 { | |
337 return &((struct funccall *)cookie)->breakpoint; | |
338 } | |
339 | |
340 /* | |
341 * Return the address holding the debug tick for a funccall cookie. | |
342 */ | |
343 int * | |
344 func_dbg_tick(cookie) | |
345 void *cookie; | |
346 { | |
347 return &((struct funccall *)cookie)->dbg_tick; | |
348 } | |
349 | |
350 /* | |
351 * Return the nesting level for a funccall cookie. | |
352 */ | |
353 int | |
354 func_level(cookie) | |
355 void *cookie; | |
356 { | |
357 return ((struct funccall *)cookie)->level; | |
358 } | |
359 | |
360 /* pointer to funccal for currently active function */ | |
361 struct funccall *current_funccal = NULL; | |
362 | |
363 /* | |
364 * Return TRUE when a function was ended by a ":return" command. | |
365 */ | |
366 int | |
367 current_func_returned() | |
368 { | |
369 return current_funccal->returned; | |
370 } | |
371 | 219 |
372 | 220 |
373 /* | 221 /* |
374 * Array to hold the value of v: variables. | 222 * Array to hold the value of v: variables. |
223 * The value is in a dictitem, so that it can also be used in the v: scope. | |
224 * The reason to use this table anyway is for very quick access to the | |
225 * variables with the VV_ defines. | |
375 */ | 226 */ |
376 #include "version.h" | 227 #include "version.h" |
377 | 228 |
378 /* values for flags: */ | 229 /* values for vv_flags: */ |
379 #define VV_COMPAT 1 /* compatible, also used without "v:" */ | 230 #define VV_COMPAT 1 /* compatible, also used without "v:" */ |
380 #define VV_RO 2 /* read-only */ | 231 #define VV_RO 2 /* read-only */ |
381 #define VV_RO_SBX 4 /* read-only in the sandbox*/ | 232 #define VV_RO_SBX 4 /* read-only in the sandbox*/ |
382 | 233 |
383 #define VV_NAME(s) s, sizeof(s) - 1 | 234 #define VV_NAME(s, t) s, sizeof(s) - 1, {{t}}, {0} |
384 | 235 |
385 struct vimvar | 236 static struct vimvar |
386 { | 237 { |
387 char *name; /* name of variable, without v: */ | 238 char *vv_name; /* name of variable, without v: */ |
388 int len; /* length of name */ | 239 int vv_len; /* length of name */ |
389 typeval tv; /* type and value */ | 240 dictitem_T vv_di; /* value and name for key */ |
390 char flags; /* VV_COMPAT, VV_RO, VV_RO_SBX */ | 241 char vv_filler[16]; /* space for LONGEST name below!!! */ |
242 char vv_flags; /* VV_COMPAT, VV_RO, VV_RO_SBX */ | |
391 } vimvars[VV_LEN] = | 243 } vimvars[VV_LEN] = |
392 { | 244 { |
393 /* | 245 /* |
394 * The order here must match the VV_ defines in vim.h! | 246 * The order here must match the VV_ defines in vim.h! |
395 * Initializing a union does not work, leave tv.vval empty to get zero's. | 247 * Initializing a union does not work, leave tv.vval empty to get zero's. |
396 */ | 248 */ |
397 {VV_NAME("count"), {VAR_NUMBER}, VV_COMPAT+VV_RO}, | 249 {VV_NAME("count", VAR_NUMBER), VV_COMPAT+VV_RO}, |
398 {VV_NAME("count1"), {VAR_NUMBER}, VV_RO}, | 250 {VV_NAME("count1", VAR_NUMBER), VV_RO}, |
399 {VV_NAME("prevcount"), {VAR_NUMBER}, VV_RO}, | 251 {VV_NAME("prevcount", VAR_NUMBER), VV_RO}, |
400 {VV_NAME("errmsg"), {VAR_STRING}, VV_COMPAT}, | 252 {VV_NAME("errmsg", VAR_STRING), VV_COMPAT}, |
401 {VV_NAME("warningmsg"), {VAR_STRING}, 0}, | 253 {VV_NAME("warningmsg", VAR_STRING), 0}, |
402 {VV_NAME("statusmsg"), {VAR_STRING}, 0}, | 254 {VV_NAME("statusmsg", VAR_STRING), 0}, |
403 {VV_NAME("shell_error"), {VAR_NUMBER}, VV_COMPAT+VV_RO}, | 255 {VV_NAME("shell_error", VAR_NUMBER), VV_COMPAT+VV_RO}, |
404 {VV_NAME("this_session"), {VAR_STRING}, VV_COMPAT}, | 256 {VV_NAME("this_session", VAR_STRING), VV_COMPAT}, |
405 {VV_NAME("version"), {VAR_NUMBER}, VV_COMPAT+VV_RO}, | 257 {VV_NAME("version", VAR_NUMBER), VV_COMPAT+VV_RO}, |
406 {VV_NAME("lnum"), {VAR_NUMBER}, VV_RO_SBX}, | 258 {VV_NAME("lnum", VAR_NUMBER), VV_RO_SBX}, |
407 {VV_NAME("termresponse"), {VAR_STRING}, VV_RO}, | 259 {VV_NAME("termresponse", VAR_STRING), VV_RO}, |
408 {VV_NAME("fname"), {VAR_STRING}, VV_RO}, | 260 {VV_NAME("fname", VAR_STRING), VV_RO}, |
409 {VV_NAME("lang"), {VAR_STRING}, VV_RO}, | 261 {VV_NAME("lang", VAR_STRING), VV_RO}, |
410 {VV_NAME("lc_time"), {VAR_STRING}, VV_RO}, | 262 {VV_NAME("lc_time", VAR_STRING), VV_RO}, |
411 {VV_NAME("ctype"), {VAR_STRING}, VV_RO}, | 263 {VV_NAME("ctype", VAR_STRING), VV_RO}, |
412 {VV_NAME("charconvert_from"), {VAR_STRING}, VV_RO}, | 264 {VV_NAME("charconvert_from", VAR_STRING), VV_RO}, |
413 {VV_NAME("charconvert_to"), {VAR_STRING}, VV_RO}, | 265 {VV_NAME("charconvert_to", VAR_STRING), VV_RO}, |
414 {VV_NAME("fname_in"), {VAR_STRING}, VV_RO}, | 266 {VV_NAME("fname_in", VAR_STRING), VV_RO}, |
415 {VV_NAME("fname_out"), {VAR_STRING}, VV_RO}, | 267 {VV_NAME("fname_out", VAR_STRING), VV_RO}, |
416 {VV_NAME("fname_new"), {VAR_STRING}, VV_RO}, | 268 {VV_NAME("fname_new", VAR_STRING), VV_RO}, |
417 {VV_NAME("fname_diff"), {VAR_STRING}, VV_RO}, | 269 {VV_NAME("fname_diff", VAR_STRING), VV_RO}, |
418 {VV_NAME("cmdarg"), {VAR_STRING}, VV_RO}, | 270 {VV_NAME("cmdarg", VAR_STRING), VV_RO}, |
419 {VV_NAME("foldstart"), {VAR_NUMBER}, VV_RO_SBX}, | 271 {VV_NAME("foldstart", VAR_NUMBER), VV_RO_SBX}, |
420 {VV_NAME("foldend"), {VAR_NUMBER}, VV_RO_SBX}, | 272 {VV_NAME("foldend", VAR_NUMBER), VV_RO_SBX}, |
421 {VV_NAME("folddashes"), {VAR_STRING}, VV_RO_SBX}, | 273 {VV_NAME("folddashes", VAR_STRING), VV_RO_SBX}, |
422 {VV_NAME("foldlevel"), {VAR_NUMBER}, VV_RO_SBX}, | 274 {VV_NAME("foldlevel", VAR_NUMBER), VV_RO_SBX}, |
423 {VV_NAME("progname"), {VAR_STRING}, VV_RO}, | 275 {VV_NAME("progname", VAR_STRING), VV_RO}, |
424 {VV_NAME("servername"), {VAR_STRING}, VV_RO}, | 276 {VV_NAME("servername", VAR_STRING), VV_RO}, |
425 {VV_NAME("dying"), {VAR_NUMBER}, VV_RO}, | 277 {VV_NAME("dying", VAR_NUMBER), VV_RO}, |
426 {VV_NAME("exception"), {VAR_STRING}, VV_RO}, | 278 {VV_NAME("exception", VAR_STRING), VV_RO}, |
427 {VV_NAME("throwpoint"), {VAR_STRING}, VV_RO}, | 279 {VV_NAME("throwpoint", VAR_STRING), VV_RO}, |
428 {VV_NAME("register"), {VAR_STRING}, VV_RO}, | 280 {VV_NAME("register", VAR_STRING), VV_RO}, |
429 {VV_NAME("cmdbang"), {VAR_NUMBER}, VV_RO}, | 281 {VV_NAME("cmdbang", VAR_NUMBER), VV_RO}, |
430 {VV_NAME("insertmode"), {VAR_STRING}, VV_RO}, | 282 {VV_NAME("insertmode", VAR_STRING), VV_RO}, |
431 {VV_NAME("val"), {VAR_UNKNOWN}, VV_RO}, | 283 {VV_NAME("val", VAR_STRING), VV_RO}, |
432 {VV_NAME("key"), {VAR_UNKNOWN}, VV_RO}, | 284 {VV_NAME("key", VAR_STRING), VV_RO}, |
433 }; | 285 }; |
434 | 286 |
435 /* shorthand */ | 287 /* shorthand */ |
436 #define vv_nr tv.vval.v_number | 288 #define vv_type vv_di.di_tv.v_type |
437 #define vv_str tv.vval.v_string | 289 #define vv_nr vv_di.di_tv.vval.v_number |
438 | 290 #define vv_str vv_di.di_tv.vval.v_string |
439 static int eval0 __ARGS((char_u *arg, typeval *rettv, char_u **nextcmd, int evaluate)); | 291 #define vv_tv vv_di.di_tv |
440 static int eval1 __ARGS((char_u **arg, typeval *rettv, int evaluate)); | 292 |
441 static int eval2 __ARGS((char_u **arg, typeval *rettv, int evaluate)); | 293 /* |
442 static int eval3 __ARGS((char_u **arg, typeval *rettv, int evaluate)); | 294 * The v: variables are stored in dictionary "vimvardict". |
443 static int eval4 __ARGS((char_u **arg, typeval *rettv, int evaluate)); | 295 * "vimvars_var" is the variable that is used for the "l:" scope. |
444 static int eval5 __ARGS((char_u **arg, typeval *rettv, int evaluate)); | 296 */ |
445 static int eval6 __ARGS((char_u **arg, typeval *rettv, int evaluate)); | 297 static dict_T vimvardict; |
446 static int eval7 __ARGS((char_u **arg, typeval *rettv, int evaluate)); | 298 static dictitem_T vimvars_var; |
447 static int eval_index __ARGS((char_u **arg, typeval *rettv, int evaluate)); | 299 #define vimvarht vimvardict.dv_hashtab |
448 static int get_option_tv __ARGS((char_u **arg, typeval *rettv, int evaluate)); | 300 |
449 static int get_string_tv __ARGS((char_u **arg, typeval *rettv, int evaluate)); | 301 static int eval0 __ARGS((char_u *arg, typval_T *rettv, char_u **nextcmd, int evaluate)); |
450 static int get_lit_string_tv __ARGS((char_u **arg, typeval *rettv, int evaluate)); | 302 static int eval1 __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
451 static int get_list_tv __ARGS((char_u **arg, typeval *rettv, int evaluate)); | 303 static int eval2 __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
452 static listvar *list_alloc __ARGS((void)); | 304 static int eval3 __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
453 static void list_unref __ARGS((listvar *l)); | 305 static int eval4 __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
454 static void list_free __ARGS((listvar *l)); | 306 static int eval5 __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
455 static listitem *listitem_alloc __ARGS((void)); | 307 static int eval6 __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
456 static void listitem_free __ARGS((listitem *item)); | 308 static int eval7 __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
457 static void listitem_remove __ARGS((listvar *l, listitem *item)); | 309 static int eval_index __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
458 static long list_len __ARGS((listvar *l)); | 310 static int get_option_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
459 static int list_equal __ARGS((listvar *l1, listvar *l2, int ic)); | 311 static int get_string_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
460 static int dict_equal __ARGS((dictvar *d1, dictvar *d2, int ic)); | 312 static int get_lit_string_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
461 static int tv_equal __ARGS((typeval *tv1, typeval *tv2, int ic)); | 313 static int get_list_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
314 static list_T *list_alloc __ARGS((void)); | |
315 static void list_unref __ARGS((list_T *l)); | |
316 static void list_free __ARGS((list_T *l)); | |
317 static listitem_T *listitem_alloc __ARGS((void)); | |
318 static void listitem_free __ARGS((listitem_T *item)); | |
319 static void listitem_remove __ARGS((list_T *l, listitem_T *item)); | |
320 static long list_len __ARGS((list_T *l)); | |
321 static int list_equal __ARGS((list_T *l1, list_T *l2, int ic)); | |
322 static int dict_equal __ARGS((dict_T *d1, dict_T *d2, int ic)); | |
323 static int tv_equal __ARGS((typval_T *tv1, typval_T *tv2, int ic)); | |
462 static int string_isa_number __ARGS((char_u *s)); | 324 static int string_isa_number __ARGS((char_u *s)); |
463 static listitem *list_find __ARGS((listvar *l, long n)); | 325 static listitem_T *list_find __ARGS((list_T *l, long n)); |
464 static long list_idx_of_item __ARGS((listvar *l, listitem *item)); | 326 static long list_idx_of_item __ARGS((list_T *l, listitem_T *item)); |
465 static listitem *list_find_ext __ARGS((listvar *l, long *ip)); | 327 static listitem_T *list_find_ext __ARGS((list_T *l, long *ip)); |
466 static void list_append __ARGS((listvar *l, listitem *item)); | 328 static void list_append __ARGS((list_T *l, listitem_T *item)); |
467 static int list_append_tv __ARGS((listvar *l, typeval *tv)); | 329 static int list_append_tv __ARGS((list_T *l, typval_T *tv)); |
468 static int list_insert_tv __ARGS((listvar *l, typeval *tv, listitem *item)); | 330 static int list_insert_tv __ARGS((list_T *l, typval_T *tv, listitem_T *item)); |
469 static int list_extend __ARGS((listvar *l1, listvar *l2, listitem *bef)); | 331 static int list_extend __ARGS((list_T *l1, list_T *l2, listitem_T *bef)); |
470 static int list_concat __ARGS((listvar *l1, listvar *l2, typeval *tv)); | 332 static int list_concat __ARGS((list_T *l1, list_T *l2, typval_T *tv)); |
471 static listvar *list_copy __ARGS((listvar *orig, int deep)); | 333 static list_T *list_copy __ARGS((list_T *orig, int deep)); |
472 static void list_remove __ARGS((listvar *l, listitem *item, listitem *item2)); | 334 static void list_remove __ARGS((list_T *l, listitem_T *item, listitem_T *item2)); |
473 static char_u *list2string __ARGS((typeval *tv)); | 335 static char_u *list2string __ARGS((typval_T *tv)); |
474 static void list_join __ARGS((garray_T *gap, listvar *l, char_u *sep, int echo)); | 336 static void list_join __ARGS((garray_T *gap, list_T *l, char_u *sep, int echo)); |
475 | 337 |
476 static dictvar *dict_alloc __ARGS((void)); | 338 static dict_T *dict_alloc __ARGS((void)); |
477 static void dict_unref __ARGS((dictvar *d)); | 339 static void dict_unref __ARGS((dict_T *d)); |
478 static void dict_free __ARGS((dictvar *d)); | 340 static void dict_free __ARGS((dict_T *d)); |
479 static dictitem *dictitem_alloc __ARGS((char_u *key)); | 341 static dictitem_T *dictitem_alloc __ARGS((char_u *key)); |
480 static dictitem *dictitem_copy __ARGS((dictitem *org)); | 342 static dictitem_T *dictitem_copy __ARGS((dictitem_T *org)); |
481 static void dictitem_remove __ARGS((dictvar *dict, dictitem *item)); | 343 static void dictitem_remove __ARGS((dict_T *dict, dictitem_T *item)); |
482 static void dictitem_free __ARGS((dictitem *item)); | 344 static void dictitem_free __ARGS((dictitem_T *item)); |
483 static int dict_add __ARGS((dictvar *d, dictitem *item)); | 345 static int dict_add __ARGS((dict_T *d, dictitem_T *item)); |
484 static long dict_len __ARGS((dictvar *d)); | 346 static long dict_len __ARGS((dict_T *d)); |
485 static dictitem *dict_find __ARGS((dictvar *d, char_u *key, int len)); | 347 static dictitem_T *dict_find __ARGS((dict_T *d, char_u *key, int len)); |
486 static char_u *dict2string __ARGS((typeval *tv)); | 348 static char_u *dict2string __ARGS((typval_T *tv)); |
487 static int get_dict_tv __ARGS((char_u **arg, typeval *rettv, int evaluate)); | 349 static int get_dict_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
488 | 350 |
489 static char_u *echo_string __ARGS((typeval *tv, char_u **tofree, char_u *numbuf)); | 351 static char_u *echo_string __ARGS((typval_T *tv, char_u **tofree, char_u *numbuf)); |
490 static char_u *tv2string __ARGS((typeval *tv, char_u **tofree, char_u *numbuf)); | 352 static char_u *tv2string __ARGS((typval_T *tv, char_u **tofree, char_u *numbuf)); |
491 static char_u *string_quote __ARGS((char_u *str, int function)); | 353 static char_u *string_quote __ARGS((char_u *str, int function)); |
492 static int get_env_tv __ARGS((char_u **arg, typeval *rettv, int evaluate)); | 354 static int get_env_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
493 static int find_internal_func __ARGS((char_u *name)); | 355 static int find_internal_func __ARGS((char_u *name)); |
494 static char_u *deref_func_name __ARGS((char_u *name, int *lenp)); | 356 static char_u *deref_func_name __ARGS((char_u *name, int *lenp)); |
495 static int get_func_tv __ARGS((char_u *name, int len, typeval *rettv, char_u **arg, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dictvar *selfdict)); | 357 static int get_func_tv __ARGS((char_u *name, int len, typval_T *rettv, char_u **arg, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict)); |
496 static int call_func __ARGS((char_u *name, int len, typeval *rettv, int argcount, typeval *argvars, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dictvar *selfdict)); | 358 static int call_func __ARGS((char_u *name, int len, typval_T *rettv, int argcount, typval_T *argvars, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict)); |
497 | 359 |
498 static void f_add __ARGS((typeval *argvars, typeval *rettv)); | 360 static void f_add __ARGS((typval_T *argvars, typval_T *rettv)); |
499 static void f_append __ARGS((typeval *argvars, typeval *rettv)); | 361 static void f_append __ARGS((typval_T *argvars, typval_T *rettv)); |
500 static void f_argc __ARGS((typeval *argvars, typeval *rettv)); | 362 static void f_argc __ARGS((typval_T *argvars, typval_T *rettv)); |
501 static void f_argidx __ARGS((typeval *argvars, typeval *rettv)); | 363 static void f_argidx __ARGS((typval_T *argvars, typval_T *rettv)); |
502 static void f_argv __ARGS((typeval *argvars, typeval *rettv)); | 364 static void f_argv __ARGS((typval_T *argvars, typval_T *rettv)); |
503 static void f_browse __ARGS((typeval *argvars, typeval *rettv)); | 365 static void f_browse __ARGS((typval_T *argvars, typval_T *rettv)); |
504 static void f_browsedir __ARGS((typeval *argvars, typeval *rettv)); | 366 static void f_browsedir __ARGS((typval_T *argvars, typval_T *rettv)); |
505 static void f_bufexists __ARGS((typeval *argvars, typeval *rettv)); | 367 static void f_bufexists __ARGS((typval_T *argvars, typval_T *rettv)); |
506 static void f_buflisted __ARGS((typeval *argvars, typeval *rettv)); | 368 static void f_buflisted __ARGS((typval_T *argvars, typval_T *rettv)); |
507 static void f_bufloaded __ARGS((typeval *argvars, typeval *rettv)); | 369 static void f_bufloaded __ARGS((typval_T *argvars, typval_T *rettv)); |
508 static void f_bufname __ARGS((typeval *argvars, typeval *rettv)); | 370 static void f_bufname __ARGS((typval_T *argvars, typval_T *rettv)); |
509 static void f_bufnr __ARGS((typeval *argvars, typeval *rettv)); | 371 static void f_bufnr __ARGS((typval_T *argvars, typval_T *rettv)); |
510 static void f_bufwinnr __ARGS((typeval *argvars, typeval *rettv)); | 372 static void f_bufwinnr __ARGS((typval_T *argvars, typval_T *rettv)); |
511 static void f_byte2line __ARGS((typeval *argvars, typeval *rettv)); | 373 static void f_byte2line __ARGS((typval_T *argvars, typval_T *rettv)); |
512 static void f_byteidx __ARGS((typeval *argvars, typeval *rettv)); | 374 static void f_byteidx __ARGS((typval_T *argvars, typval_T *rettv)); |
513 static void f_call __ARGS((typeval *argvars, typeval *rettv)); | 375 static void f_call __ARGS((typval_T *argvars, typval_T *rettv)); |
514 static void f_char2nr __ARGS((typeval *argvars, typeval *rettv)); | 376 static void f_char2nr __ARGS((typval_T *argvars, typval_T *rettv)); |
515 static void f_cindent __ARGS((typeval *argvars, typeval *rettv)); | 377 static void f_cindent __ARGS((typval_T *argvars, typval_T *rettv)); |
516 static void f_col __ARGS((typeval *argvars, typeval *rettv)); | 378 static void f_col __ARGS((typval_T *argvars, typval_T *rettv)); |
517 static void f_confirm __ARGS((typeval *argvars, typeval *rettv)); | 379 static void f_confirm __ARGS((typval_T *argvars, typval_T *rettv)); |
518 static void f_copy __ARGS((typeval *argvars, typeval *rettv)); | 380 static void f_copy __ARGS((typval_T *argvars, typval_T *rettv)); |
519 static void f_count __ARGS((typeval *argvars, typeval *rettv)); | 381 static void f_count __ARGS((typval_T *argvars, typval_T *rettv)); |
520 static void f_cscope_connection __ARGS((typeval *argvars, typeval *rettv)); | 382 static void f_cscope_connection __ARGS((typval_T *argvars, typval_T *rettv)); |
521 static void f_cursor __ARGS((typeval *argsvars, typeval *rettv)); | 383 static void f_cursor __ARGS((typval_T *argsvars, typval_T *rettv)); |
522 static void f_deepcopy __ARGS((typeval *argvars, typeval *rettv)); | 384 static void f_deepcopy __ARGS((typval_T *argvars, typval_T *rettv)); |
523 static void f_delete __ARGS((typeval *argvars, typeval *rettv)); | 385 static void f_delete __ARGS((typval_T *argvars, typval_T *rettv)); |
524 static void f_did_filetype __ARGS((typeval *argvars, typeval *rettv)); | 386 static void f_did_filetype __ARGS((typval_T *argvars, typval_T *rettv)); |
525 static void f_diff_filler __ARGS((typeval *argvars, typeval *rettv)); | 387 static void f_diff_filler __ARGS((typval_T *argvars, typval_T *rettv)); |
526 static void f_diff_hlID __ARGS((typeval *argvars, typeval *rettv)); | 388 static void f_diff_hlID __ARGS((typval_T *argvars, typval_T *rettv)); |
527 static void f_empty __ARGS((typeval *argvars, typeval *rettv)); | 389 static void f_empty __ARGS((typval_T *argvars, typval_T *rettv)); |
528 static void f_escape __ARGS((typeval *argvars, typeval *rettv)); | 390 static void f_escape __ARGS((typval_T *argvars, typval_T *rettv)); |
529 static void f_eval __ARGS((typeval *argvars, typeval *rettv)); | 391 static void f_eval __ARGS((typval_T *argvars, typval_T *rettv)); |
530 static void f_eventhandler __ARGS((typeval *argvars, typeval *rettv)); | 392 static void f_eventhandler __ARGS((typval_T *argvars, typval_T *rettv)); |
531 static void f_executable __ARGS((typeval *argvars, typeval *rettv)); | 393 static void f_executable __ARGS((typval_T *argvars, typval_T *rettv)); |
532 static void f_exists __ARGS((typeval *argvars, typeval *rettv)); | 394 static void f_exists __ARGS((typval_T *argvars, typval_T *rettv)); |
533 static void f_expand __ARGS((typeval *argvars, typeval *rettv)); | 395 static void f_expand __ARGS((typval_T *argvars, typval_T *rettv)); |
534 static void f_extend __ARGS((typeval *argvars, typeval *rettv)); | 396 static void f_extend __ARGS((typval_T *argvars, typval_T *rettv)); |
535 static void f_filereadable __ARGS((typeval *argvars, typeval *rettv)); | 397 static void f_filereadable __ARGS((typval_T *argvars, typval_T *rettv)); |
536 static void f_filewritable __ARGS((typeval *argvars, typeval *rettv)); | 398 static void f_filewritable __ARGS((typval_T *argvars, typval_T *rettv)); |
537 static void f_filter __ARGS((typeval *argvars, typeval *rettv)); | 399 static void f_filter __ARGS((typval_T *argvars, typval_T *rettv)); |
538 static void f_finddir __ARGS((typeval *argvars, typeval *rettv)); | 400 static void f_finddir __ARGS((typval_T *argvars, typval_T *rettv)); |
539 static void f_findfile __ARGS((typeval *argvars, typeval *rettv)); | 401 static void f_findfile __ARGS((typval_T *argvars, typval_T *rettv)); |
540 static void f_fnamemodify __ARGS((typeval *argvars, typeval *rettv)); | 402 static void f_fnamemodify __ARGS((typval_T *argvars, typval_T *rettv)); |
541 static void f_foldclosed __ARGS((typeval *argvars, typeval *rettv)); | 403 static void f_foldclosed __ARGS((typval_T *argvars, typval_T *rettv)); |
542 static void f_foldclosedend __ARGS((typeval *argvars, typeval *rettv)); | 404 static void f_foldclosedend __ARGS((typval_T *argvars, typval_T *rettv)); |
543 static void f_foldlevel __ARGS((typeval *argvars, typeval *rettv)); | 405 static void f_foldlevel __ARGS((typval_T *argvars, typval_T *rettv)); |
544 static void f_foldtext __ARGS((typeval *argvars, typeval *rettv)); | 406 static void f_foldtext __ARGS((typval_T *argvars, typval_T *rettv)); |
545 static void f_foldtextresult __ARGS((typeval *argvars, typeval *rettv)); | 407 static void f_foldtextresult __ARGS((typval_T *argvars, typval_T *rettv)); |
546 static void f_foreground __ARGS((typeval *argvars, typeval *rettv)); | 408 static void f_foreground __ARGS((typval_T *argvars, typval_T *rettv)); |
547 static void f_function __ARGS((typeval *argvars, typeval *rettv)); | 409 static void f_function __ARGS((typval_T *argvars, typval_T *rettv)); |
548 static void f_get __ARGS((typeval *argvars, typeval *rettv)); | 410 static void f_get __ARGS((typval_T *argvars, typval_T *rettv)); |
549 static void f_getbufvar __ARGS((typeval *argvars, typeval *rettv)); | 411 static void f_getbufvar __ARGS((typval_T *argvars, typval_T *rettv)); |
550 static void f_getchar __ARGS((typeval *argvars, typeval *rettv)); | 412 static void f_getchar __ARGS((typval_T *argvars, typval_T *rettv)); |
551 static void f_getcharmod __ARGS((typeval *argvars, typeval *rettv)); | 413 static void f_getcharmod __ARGS((typval_T *argvars, typval_T *rettv)); |
552 static void f_getcmdline __ARGS((typeval *argvars, typeval *rettv)); | 414 static void f_getcmdline __ARGS((typval_T *argvars, typval_T *rettv)); |
553 static void f_getcmdpos __ARGS((typeval *argvars, typeval *rettv)); | 415 static void f_getcmdpos __ARGS((typval_T *argvars, typval_T *rettv)); |
554 static void f_getcwd __ARGS((typeval *argvars, typeval *rettv)); | 416 static void f_getcwd __ARGS((typval_T *argvars, typval_T *rettv)); |
555 static void f_getfontname __ARGS((typeval *argvars, typeval *rettv)); | 417 static void f_getfontname __ARGS((typval_T *argvars, typval_T *rettv)); |
556 static void f_getfperm __ARGS((typeval *argvars, typeval *rettv)); | 418 static void f_getfperm __ARGS((typval_T *argvars, typval_T *rettv)); |
557 static void f_getfsize __ARGS((typeval *argvars, typeval *rettv)); | 419 static void f_getfsize __ARGS((typval_T *argvars, typval_T *rettv)); |
558 static void f_getftime __ARGS((typeval *argvars, typeval *rettv)); | 420 static void f_getftime __ARGS((typval_T *argvars, typval_T *rettv)); |
559 static void f_getftype __ARGS((typeval *argvars, typeval *rettv)); | 421 static void f_getftype __ARGS((typval_T *argvars, typval_T *rettv)); |
560 static void f_getline __ARGS((typeval *argvars, typeval *rettv)); | 422 static void f_getline __ARGS((typval_T *argvars, typval_T *rettv)); |
561 static void f_getreg __ARGS((typeval *argvars, typeval *rettv)); | 423 static void f_getreg __ARGS((typval_T *argvars, typval_T *rettv)); |
562 static void f_getregtype __ARGS((typeval *argvars, typeval *rettv)); | 424 static void f_getregtype __ARGS((typval_T *argvars, typval_T *rettv)); |
563 static void f_getwinposx __ARGS((typeval *argvars, typeval *rettv)); | 425 static void f_getwinposx __ARGS((typval_T *argvars, typval_T *rettv)); |
564 static void f_getwinposy __ARGS((typeval *argvars, typeval *rettv)); | 426 static void f_getwinposy __ARGS((typval_T *argvars, typval_T *rettv)); |
565 static void f_getwinvar __ARGS((typeval *argvars, typeval *rettv)); | 427 static void f_getwinvar __ARGS((typval_T *argvars, typval_T *rettv)); |
566 static void f_glob __ARGS((typeval *argvars, typeval *rettv)); | 428 static void f_glob __ARGS((typval_T *argvars, typval_T *rettv)); |
567 static void f_globpath __ARGS((typeval *argvars, typeval *rettv)); | 429 static void f_globpath __ARGS((typval_T *argvars, typval_T *rettv)); |
568 static void f_has __ARGS((typeval *argvars, typeval *rettv)); | 430 static void f_has __ARGS((typval_T *argvars, typval_T *rettv)); |
569 static void f_has_key __ARGS((typeval *argvars, typeval *rettv)); | 431 static void f_has_key __ARGS((typval_T *argvars, typval_T *rettv)); |
570 static void f_hasmapto __ARGS((typeval *argvars, typeval *rettv)); | 432 static void f_hasmapto __ARGS((typval_T *argvars, typval_T *rettv)); |
571 static void f_histadd __ARGS((typeval *argvars, typeval *rettv)); | 433 static void f_histadd __ARGS((typval_T *argvars, typval_T *rettv)); |
572 static void f_histdel __ARGS((typeval *argvars, typeval *rettv)); | 434 static void f_histdel __ARGS((typval_T *argvars, typval_T *rettv)); |
573 static void f_histget __ARGS((typeval *argvars, typeval *rettv)); | 435 static void f_histget __ARGS((typval_T *argvars, typval_T *rettv)); |
574 static void f_histnr __ARGS((typeval *argvars, typeval *rettv)); | 436 static void f_histnr __ARGS((typval_T *argvars, typval_T *rettv)); |
575 static void f_hlID __ARGS((typeval *argvars, typeval *rettv)); | 437 static void f_hlID __ARGS((typval_T *argvars, typval_T *rettv)); |
576 static void f_hlexists __ARGS((typeval *argvars, typeval *rettv)); | 438 static void f_hlexists __ARGS((typval_T *argvars, typval_T *rettv)); |
577 static void f_hostname __ARGS((typeval *argvars, typeval *rettv)); | 439 static void f_hostname __ARGS((typval_T *argvars, typval_T *rettv)); |
578 static void f_iconv __ARGS((typeval *argvars, typeval *rettv)); | 440 static void f_iconv __ARGS((typval_T *argvars, typval_T *rettv)); |
579 static void f_indent __ARGS((typeval *argvars, typeval *rettv)); | 441 static void f_indent __ARGS((typval_T *argvars, typval_T *rettv)); |
580 static void f_index __ARGS((typeval *argvars, typeval *rettv)); | 442 static void f_index __ARGS((typval_T *argvars, typval_T *rettv)); |
581 static void f_input __ARGS((typeval *argvars, typeval *rettv)); | 443 static void f_input __ARGS((typval_T *argvars, typval_T *rettv)); |
582 static void f_inputdialog __ARGS((typeval *argvars, typeval *rettv)); | 444 static void f_inputdialog __ARGS((typval_T *argvars, typval_T *rettv)); |
583 static void f_inputrestore __ARGS((typeval *argvars, typeval *rettv)); | 445 static void f_inputrestore __ARGS((typval_T *argvars, typval_T *rettv)); |
584 static void f_inputsave __ARGS((typeval *argvars, typeval *rettv)); | 446 static void f_inputsave __ARGS((typval_T *argvars, typval_T *rettv)); |
585 static void f_inputsecret __ARGS((typeval *argvars, typeval *rettv)); | 447 static void f_inputsecret __ARGS((typval_T *argvars, typval_T *rettv)); |
586 static void f_insert __ARGS((typeval *argvars, typeval *rettv)); | 448 static void f_insert __ARGS((typval_T *argvars, typval_T *rettv)); |
587 static void f_isdirectory __ARGS((typeval *argvars, typeval *rettv)); | 449 static void f_isdirectory __ARGS((typval_T *argvars, typval_T *rettv)); |
588 static void f_items __ARGS((typeval *argvars, typeval *rettv)); | 450 static void f_items __ARGS((typval_T *argvars, typval_T *rettv)); |
589 static void f_join __ARGS((typeval *argvars, typeval *rettv)); | 451 static void f_join __ARGS((typval_T *argvars, typval_T *rettv)); |
590 static void f_keys __ARGS((typeval *argvars, typeval *rettv)); | 452 static void f_keys __ARGS((typval_T *argvars, typval_T *rettv)); |
591 static void f_last_buffer_nr __ARGS((typeval *argvars, typeval *rettv)); | 453 static void f_last_buffer_nr __ARGS((typval_T *argvars, typval_T *rettv)); |
592 static void f_len __ARGS((typeval *argvars, typeval *rettv)); | 454 static void f_len __ARGS((typval_T *argvars, typval_T *rettv)); |
593 static void f_libcall __ARGS((typeval *argvars, typeval *rettv)); | 455 static void f_libcall __ARGS((typval_T *argvars, typval_T *rettv)); |
594 static void f_libcallnr __ARGS((typeval *argvars, typeval *rettv)); | 456 static void f_libcallnr __ARGS((typval_T *argvars, typval_T *rettv)); |
595 static void f_line __ARGS((typeval *argvars, typeval *rettv)); | 457 static void f_line __ARGS((typval_T *argvars, typval_T *rettv)); |
596 static void f_line2byte __ARGS((typeval *argvars, typeval *rettv)); | 458 static void f_line2byte __ARGS((typval_T *argvars, typval_T *rettv)); |
597 static void f_lispindent __ARGS((typeval *argvars, typeval *rettv)); | 459 static void f_lispindent __ARGS((typval_T *argvars, typval_T *rettv)); |
598 static void f_localtime __ARGS((typeval *argvars, typeval *rettv)); | 460 static void f_localtime __ARGS((typval_T *argvars, typval_T *rettv)); |
599 static void f_map __ARGS((typeval *argvars, typeval *rettv)); | 461 static void f_map __ARGS((typval_T *argvars, typval_T *rettv)); |
600 static void f_maparg __ARGS((typeval *argvars, typeval *rettv)); | 462 static void f_maparg __ARGS((typval_T *argvars, typval_T *rettv)); |
601 static void f_mapcheck __ARGS((typeval *argvars, typeval *rettv)); | 463 static void f_mapcheck __ARGS((typval_T *argvars, typval_T *rettv)); |
602 static void f_match __ARGS((typeval *argvars, typeval *rettv)); | 464 static void f_match __ARGS((typval_T *argvars, typval_T *rettv)); |
603 static void f_matchend __ARGS((typeval *argvars, typeval *rettv)); | 465 static void f_matchend __ARGS((typval_T *argvars, typval_T *rettv)); |
604 static void f_matchstr __ARGS((typeval *argvars, typeval *rettv)); | 466 static void f_matchstr __ARGS((typval_T *argvars, typval_T *rettv)); |
605 static void f_max __ARGS((typeval *argvars, typeval *rettv)); | 467 static void f_max __ARGS((typval_T *argvars, typval_T *rettv)); |
606 static void f_min __ARGS((typeval *argvars, typeval *rettv)); | 468 static void f_min __ARGS((typval_T *argvars, typval_T *rettv)); |
607 static void f_mode __ARGS((typeval *argvars, typeval *rettv)); | 469 static void f_mode __ARGS((typval_T *argvars, typval_T *rettv)); |
608 static void f_nextnonblank __ARGS((typeval *argvars, typeval *rettv)); | 470 static void f_nextnonblank __ARGS((typval_T *argvars, typval_T *rettv)); |
609 static void f_nr2char __ARGS((typeval *argvars, typeval *rettv)); | 471 static void f_nr2char __ARGS((typval_T *argvars, typval_T *rettv)); |
610 static void f_prevnonblank __ARGS((typeval *argvars, typeval *rettv)); | 472 static void f_prevnonblank __ARGS((typval_T *argvars, typval_T *rettv)); |
611 static void f_range __ARGS((typeval *argvars, typeval *rettv)); | 473 static void f_range __ARGS((typval_T *argvars, typval_T *rettv)); |
612 static void f_remote_expr __ARGS((typeval *argvars, typeval *rettv)); | 474 static void f_remote_expr __ARGS((typval_T *argvars, typval_T *rettv)); |
613 static void f_remote_foreground __ARGS((typeval *argvars, typeval *rettv)); | 475 static void f_remote_foreground __ARGS((typval_T *argvars, typval_T *rettv)); |
614 static void f_remote_peek __ARGS((typeval *argvars, typeval *rettv)); | 476 static void f_remote_peek __ARGS((typval_T *argvars, typval_T *rettv)); |
615 static void f_remote_read __ARGS((typeval *argvars, typeval *rettv)); | 477 static void f_remote_read __ARGS((typval_T *argvars, typval_T *rettv)); |
616 static void f_remote_send __ARGS((typeval *argvars, typeval *rettv)); | 478 static void f_remote_send __ARGS((typval_T *argvars, typval_T *rettv)); |
617 static void f_remove __ARGS((typeval *argvars, typeval *rettv)); | 479 static void f_remove __ARGS((typval_T *argvars, typval_T *rettv)); |
618 static void f_rename __ARGS((typeval *argvars, typeval *rettv)); | 480 static void f_rename __ARGS((typval_T *argvars, typval_T *rettv)); |
619 static void f_repeat __ARGS((typeval *argvars, typeval *rettv)); | 481 static void f_repeat __ARGS((typval_T *argvars, typval_T *rettv)); |
620 static void f_resolve __ARGS((typeval *argvars, typeval *rettv)); | 482 static void f_resolve __ARGS((typval_T *argvars, typval_T *rettv)); |
621 static void f_reverse __ARGS((typeval *argvars, typeval *rettv)); | 483 static void f_reverse __ARGS((typval_T *argvars, typval_T *rettv)); |
622 static void f_search __ARGS((typeval *argvars, typeval *rettv)); | 484 static void f_search __ARGS((typval_T *argvars, typval_T *rettv)); |
623 static void f_searchpair __ARGS((typeval *argvars, typeval *rettv)); | 485 static void f_searchpair __ARGS((typval_T *argvars, typval_T *rettv)); |
624 static void f_server2client __ARGS((typeval *argvars, typeval *rettv)); | 486 static void f_server2client __ARGS((typval_T *argvars, typval_T *rettv)); |
625 static void f_serverlist __ARGS((typeval *argvars, typeval *rettv)); | 487 static void f_serverlist __ARGS((typval_T *argvars, typval_T *rettv)); |
626 static void f_setbufvar __ARGS((typeval *argvars, typeval *rettv)); | 488 static void f_setbufvar __ARGS((typval_T *argvars, typval_T *rettv)); |
627 static void f_setcmdpos __ARGS((typeval *argvars, typeval *rettv)); | 489 static void f_setcmdpos __ARGS((typval_T *argvars, typval_T *rettv)); |
628 static void f_setline __ARGS((typeval *argvars, typeval *rettv)); | 490 static void f_setline __ARGS((typval_T *argvars, typval_T *rettv)); |
629 static void f_setreg __ARGS((typeval *argvars, typeval *rettv)); | 491 static void f_setreg __ARGS((typval_T *argvars, typval_T *rettv)); |
630 static void f_setwinvar __ARGS((typeval *argvars, typeval *rettv)); | 492 static void f_setwinvar __ARGS((typval_T *argvars, typval_T *rettv)); |
631 static void f_simplify __ARGS((typeval *argvars, typeval *rettv)); | 493 static void f_simplify __ARGS((typval_T *argvars, typval_T *rettv)); |
632 static void f_sort __ARGS((typeval *argvars, typeval *rettv)); | 494 static void f_sort __ARGS((typval_T *argvars, typval_T *rettv)); |
633 static void f_split __ARGS((typeval *argvars, typeval *rettv)); | 495 static void f_split __ARGS((typval_T *argvars, typval_T *rettv)); |
634 #ifdef HAVE_STRFTIME | 496 #ifdef HAVE_STRFTIME |
635 static void f_strftime __ARGS((typeval *argvars, typeval *rettv)); | 497 static void f_strftime __ARGS((typval_T *argvars, typval_T *rettv)); |
636 #endif | 498 #endif |
637 static void f_stridx __ARGS((typeval *argvars, typeval *rettv)); | 499 static void f_stridx __ARGS((typval_T *argvars, typval_T *rettv)); |
638 static void f_string __ARGS((typeval *argvars, typeval *rettv)); | 500 static void f_string __ARGS((typval_T *argvars, typval_T *rettv)); |
639 static void f_strlen __ARGS((typeval *argvars, typeval *rettv)); | 501 static void f_strlen __ARGS((typval_T *argvars, typval_T *rettv)); |
640 static void f_strpart __ARGS((typeval *argvars, typeval *rettv)); | 502 static void f_strpart __ARGS((typval_T *argvars, typval_T *rettv)); |
641 static void f_strridx __ARGS((typeval *argvars, typeval *rettv)); | 503 static void f_strridx __ARGS((typval_T *argvars, typval_T *rettv)); |
642 static void f_strtrans __ARGS((typeval *argvars, typeval *rettv)); | 504 static void f_strtrans __ARGS((typval_T *argvars, typval_T *rettv)); |
643 static void f_submatch __ARGS((typeval *argvars, typeval *rettv)); | 505 static void f_submatch __ARGS((typval_T *argvars, typval_T *rettv)); |
644 static void f_substitute __ARGS((typeval *argvars, typeval *rettv)); | 506 static void f_substitute __ARGS((typval_T *argvars, typval_T *rettv)); |
645 static void f_synID __ARGS((typeval *argvars, typeval *rettv)); | 507 static void f_synID __ARGS((typval_T *argvars, typval_T *rettv)); |
646 static void f_synIDattr __ARGS((typeval *argvars, typeval *rettv)); | 508 static void f_synIDattr __ARGS((typval_T *argvars, typval_T *rettv)); |
647 static void f_synIDtrans __ARGS((typeval *argvars, typeval *rettv)); | 509 static void f_synIDtrans __ARGS((typval_T *argvars, typval_T *rettv)); |
648 static void f_system __ARGS((typeval *argvars, typeval *rettv)); | 510 static void f_system __ARGS((typval_T *argvars, typval_T *rettv)); |
649 static void f_tempname __ARGS((typeval *argvars, typeval *rettv)); | 511 static void f_tempname __ARGS((typval_T *argvars, typval_T *rettv)); |
650 static void f_tolower __ARGS((typeval *argvars, typeval *rettv)); | 512 static void f_tolower __ARGS((typval_T *argvars, typval_T *rettv)); |
651 static void f_toupper __ARGS((typeval *argvars, typeval *rettv)); | 513 static void f_toupper __ARGS((typval_T *argvars, typval_T *rettv)); |
652 static void f_tr __ARGS((typeval *argvars, typeval *rettv)); | 514 static void f_tr __ARGS((typval_T *argvars, typval_T *rettv)); |
653 static void f_type __ARGS((typeval *argvars, typeval *rettv)); | 515 static void f_type __ARGS((typval_T *argvars, typval_T *rettv)); |
654 static void f_values __ARGS((typeval *argvars, typeval *rettv)); | 516 static void f_values __ARGS((typval_T *argvars, typval_T *rettv)); |
655 static void f_virtcol __ARGS((typeval *argvars, typeval *rettv)); | 517 static void f_virtcol __ARGS((typval_T *argvars, typval_T *rettv)); |
656 static void f_visualmode __ARGS((typeval *argvars, typeval *rettv)); | 518 static void f_visualmode __ARGS((typval_T *argvars, typval_T *rettv)); |
657 static void f_winbufnr __ARGS((typeval *argvars, typeval *rettv)); | 519 static void f_winbufnr __ARGS((typval_T *argvars, typval_T *rettv)); |
658 static void f_wincol __ARGS((typeval *argvars, typeval *rettv)); | 520 static void f_wincol __ARGS((typval_T *argvars, typval_T *rettv)); |
659 static void f_winheight __ARGS((typeval *argvars, typeval *rettv)); | 521 static void f_winheight __ARGS((typval_T *argvars, typval_T *rettv)); |
660 static void f_winline __ARGS((typeval *argvars, typeval *rettv)); | 522 static void f_winline __ARGS((typval_T *argvars, typval_T *rettv)); |
661 static void f_winnr __ARGS((typeval *argvars, typeval *rettv)); | 523 static void f_winnr __ARGS((typval_T *argvars, typval_T *rettv)); |
662 static void f_winrestcmd __ARGS((typeval *argvars, typeval *rettv)); | 524 static void f_winrestcmd __ARGS((typval_T *argvars, typval_T *rettv)); |
663 static void f_winwidth __ARGS((typeval *argvars, typeval *rettv)); | 525 static void f_winwidth __ARGS((typval_T *argvars, typval_T *rettv)); |
664 | 526 |
665 static win_T *find_win_by_nr __ARGS((typeval *vp)); | 527 static win_T *find_win_by_nr __ARGS((typval_T *vp)); |
666 static pos_T *var2fpos __ARGS((typeval *varp, int lnum)); | 528 static pos_T *var2fpos __ARGS((typval_T *varp, int lnum)); |
667 static int get_env_len __ARGS((char_u **arg)); | 529 static int get_env_len __ARGS((char_u **arg)); |
668 static int get_id_len __ARGS((char_u **arg)); | 530 static int get_id_len __ARGS((char_u **arg)); |
669 static int get_name_len __ARGS((char_u **arg, char_u **alias, int evaluate)); | 531 static int get_name_len __ARGS((char_u **arg, char_u **alias, int evaluate)); |
670 static char_u *find_name_end __ARGS((char_u *arg, char_u **expr_start, char_u **expr_end, int incl_br)); | 532 static char_u *find_name_end __ARGS((char_u *arg, char_u **expr_start, char_u **expr_end, int incl_br)); |
671 static int eval_isnamec __ARGS((int c)); | 533 static int eval_isnamec __ARGS((int c)); |
672 static int find_vim_var __ARGS((char_u *name, int len)); | 534 static int get_var_tv __ARGS((char_u *name, int len, typval_T *rettv)); |
673 static int get_var_tv __ARGS((char_u *name, int len, typeval *rettv)); | 535 static typval_T *alloc_tv __ARGS((void)); |
674 static typeval *alloc_tv __ARGS((void)); | 536 static typval_T *alloc_string_tv __ARGS((char_u *string)); |
675 static typeval *alloc_string_tv __ARGS((char_u *string)); | 537 static void free_tv __ARGS((typval_T *varp)); |
676 static void free_tv __ARGS((typeval *varp)); | 538 static void clear_tv __ARGS((typval_T *varp)); |
677 static void clear_tv __ARGS((typeval *varp)); | 539 static void init_tv __ARGS((typval_T *varp)); |
678 static void init_tv __ARGS((typeval *varp)); | 540 static long get_tv_number __ARGS((typval_T *varp)); |
679 static long get_tv_number __ARGS((typeval *varp)); | 541 static linenr_T get_tv_lnum __ARGS((typval_T *argvars)); |
680 static linenr_T get_tv_lnum __ARGS((typeval *argvars)); | 542 static char_u *get_tv_string __ARGS((typval_T *varp)); |
681 static char_u *get_tv_string __ARGS((typeval *varp)); | 543 static char_u *get_tv_string_buf __ARGS((typval_T *varp, char_u *buf)); |
682 static char_u *get_tv_string_buf __ARGS((typeval *varp, char_u *buf)); | 544 static dictitem_T *find_var __ARGS((char_u *name, hashtab_T **htp)); |
683 static VAR find_var __ARGS((char_u *name, hashtable **htp)); | 545 static dictitem_T *find_var_in_ht __ARGS((hashtab_T *ht, char_u *varname)); |
684 static VAR find_var_in_ht __ARGS((hashtable *ht, char_u *varname)); | 546 static hashtab_T *find_var_ht __ARGS((char_u *name, char_u **varname)); |
685 static hashtable *find_var_ht __ARGS((char_u *name, char_u **varname)); | 547 static void vars_clear_ext __ARGS((hashtab_T *ht, int free_val)); |
686 static void delete_var __ARGS((hashtable *ht, hashitem *hi)); | 548 static void delete_var __ARGS((hashtab_T *ht, hashitem_T *hi)); |
687 static void list_one_var __ARGS((VAR v, char_u *prefix)); | 549 static void list_one_var __ARGS((dictitem_T *v, char_u *prefix)); |
688 static void list_vim_var __ARGS((int i)); | |
689 static void list_one_var_a __ARGS((char_u *prefix, char_u *name, int type, char_u *string)); | 550 static void list_one_var_a __ARGS((char_u *prefix, char_u *name, int type, char_u *string)); |
690 static void set_var __ARGS((char_u *name, typeval *varp, int copy)); | 551 static void set_var __ARGS((char_u *name, typval_T *varp, int copy)); |
691 static void copy_tv __ARGS((typeval *from, typeval *to)); | 552 static int var_check_ro __ARGS((int flags, char_u *name)); |
692 static void item_copy __ARGS((typeval *from, typeval *to, int deep)); | 553 static void copy_tv __ARGS((typval_T *from, typval_T *to)); |
554 static void item_copy __ARGS((typval_T *from, typval_T *to, int deep)); | |
693 static char_u *find_option_end __ARGS((char_u **arg, int *opt_flags)); | 555 static char_u *find_option_end __ARGS((char_u **arg, int *opt_flags)); |
694 static char_u *trans_function_name __ARGS((char_u **pp, int skip, int flags, funcdict *fd)); | 556 static char_u *trans_function_name __ARGS((char_u **pp, int skip, int flags, funcdict_T *fd)); |
695 static int eval_fname_script __ARGS((char_u *p)); | 557 static int eval_fname_script __ARGS((char_u *p)); |
696 static int eval_fname_sid __ARGS((char_u *p)); | 558 static int eval_fname_sid __ARGS((char_u *p)); |
697 static void list_func_head __ARGS((ufunc_T *fp, int indent)); | 559 static void list_func_head __ARGS((ufunc_T *fp, int indent)); |
698 static void cat_func_name __ARGS((char_u *buf, ufunc_T *fp)); | 560 static void cat_func_name __ARGS((char_u *buf, ufunc_T *fp)); |
699 static ufunc_T *find_func __ARGS((char_u *name)); | 561 static ufunc_T *find_func __ARGS((char_u *name)); |
700 static int function_exists __ARGS((char_u *name)); | 562 static int function_exists __ARGS((char_u *name)); |
701 static void func_free __ARGS((ufunc_T *fp)); | 563 static void func_free __ARGS((ufunc_T *fp)); |
702 static void func_unref __ARGS((char_u *name)); | 564 static void func_unref __ARGS((char_u *name)); |
703 static void func_ref __ARGS((char_u *name)); | 565 static void func_ref __ARGS((char_u *name)); |
704 static void call_user_func __ARGS((ufunc_T *fp, int argcount, typeval *argvars, typeval *rettv, linenr_T firstline, linenr_T lastline, dictvar *selfdict)); | 566 static void call_user_func __ARGS((ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, linenr_T firstline, linenr_T lastline, dict_T *selfdict)); |
567 static void add_nr_var __ARGS((dict_T *dp, dictitem_T *v, char *name, varnumber_T nr)); | |
705 | 568 |
706 static char_u * make_expanded_name __ARGS((char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end)); | 569 static char_u * make_expanded_name __ARGS((char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end)); |
707 | 570 |
708 static int ex_let_vars __ARGS((char_u *arg, typeval *tv, int copy, int semicolon, int var_count, char_u *nextchars)); | 571 static int ex_let_vars __ARGS((char_u *arg, typval_T *tv, int copy, int semicolon, int var_count, char_u *nextchars)); |
709 static char_u *skip_var_list __ARGS((char_u *arg, int *var_count, int *semicolon)); | 572 static char_u *skip_var_list __ARGS((char_u *arg, int *var_count, int *semicolon)); |
710 static char_u *skip_var_one __ARGS((char_u *arg)); | 573 static char_u *skip_var_one __ARGS((char_u *arg)); |
711 static void list_hashtable_vars __ARGS((hashtable *ht, char_u *prefix)); | 574 static void list_hashtable_vars __ARGS((hashtab_T *ht, char_u *prefix, int empty)); |
712 static void list_glob_vars __ARGS((void)); | 575 static void list_glob_vars __ARGS((void)); |
713 static void list_buf_vars __ARGS((void)); | 576 static void list_buf_vars __ARGS((void)); |
714 static void list_win_vars __ARGS((void)); | 577 static void list_win_vars __ARGS((void)); |
715 static void list_vim_vars __ARGS((void)); | 578 static void list_vim_vars __ARGS((void)); |
716 static char_u *list_arg_vars __ARGS((exarg_T *eap, char_u *arg)); | 579 static char_u *list_arg_vars __ARGS((exarg_T *eap, char_u *arg)); |
717 static char_u *ex_let_one __ARGS((char_u *arg, typeval *tv, int copy, char_u *endchars, char_u *op)); | 580 static char_u *ex_let_one __ARGS((char_u *arg, typval_T *tv, int copy, char_u *endchars, char_u *op)); |
718 static int check_changedtick __ARGS((char_u *arg)); | 581 static int check_changedtick __ARGS((char_u *arg)); |
719 static char_u *get_lval __ARGS((char_u *name, typeval *rettv, lval *lp, int unlet, int skip, int quiet)); | 582 static char_u *get_lval __ARGS((char_u *name, typval_T *rettv, lval_T *lp, int unlet, int skip, int quiet)); |
720 static void clear_lval __ARGS((lval *lp)); | 583 static void clear_lval __ARGS((lval_T *lp)); |
721 static void set_var_lval __ARGS((lval *lp, char_u *endp, typeval *rettv, int copy, char_u *op)); | 584 static void set_var_lval __ARGS((lval_T *lp, char_u *endp, typval_T *rettv, int copy, char_u *op)); |
722 static int tv_op __ARGS((typeval *tv1, typeval *tv2, char_u *op)); | 585 static int tv_op __ARGS((typval_T *tv1, typval_T *tv2, char_u *op)); |
723 static void list_add_watch __ARGS((listvar *l, listwatch *lw)); | 586 static void list_add_watch __ARGS((list_T *l, listwatch_T *lw)); |
724 static void list_rem_watch __ARGS((listvar *l, listwatch *lwrem)); | 587 static void list_rem_watch __ARGS((list_T *l, listwatch_T *lwrem)); |
725 static void list_fix_watch __ARGS((listvar *l, listitem *item)); | 588 static void list_fix_watch __ARGS((list_T *l, listitem_T *item)); |
726 static int do_unlet_var __ARGS((lval *lp, char_u *name_end, int forceit)); | 589 static int do_unlet_var __ARGS((lval_T *lp, char_u *name_end, int forceit)); |
590 | |
591 /* | |
592 * Initialize the global and v: variables. | |
593 */ | |
594 void | |
595 eval_init() | |
596 { | |
597 int i; | |
598 struct vimvar *p; | |
599 | |
600 init_var_dict(&globvardict, &globvars_var); | |
601 init_var_dict(&vimvardict, &vimvars_var); | |
602 | |
603 for (i = 0; i < VV_LEN; ++i) | |
604 { | |
605 p = &vimvars[i]; | |
606 STRCPY(p->vv_di.di_key, p->vv_name); | |
607 if (p->vv_flags & VV_RO) | |
608 p->vv_di.di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; | |
609 else if (p->vv_flags & VV_RO_SBX) | |
610 p->vv_di.di_flags = DI_FLAGS_RO_SBX | DI_FLAGS_FIX; | |
611 else | |
612 p->vv_di.di_flags = DI_FLAGS_FIX; | |
613 /* add to v: scope dict */ | |
614 hash_add(&vimvarht, p->vv_di.di_key); | |
615 if (p->vv_flags & VV_COMPAT) | |
616 /* add to g: scope dict */ | |
617 hash_add(&globvardict.dv_hashtab, p->vv_di.di_key); | |
618 } | |
619 } | |
620 | |
621 /* | |
622 * Return the name of the executed function. | |
623 */ | |
624 char_u * | |
625 func_name(cookie) | |
626 void *cookie; | |
627 { | |
628 return ((funccall_T *)cookie)->func->name; | |
629 } | |
630 | |
631 /* | |
632 * Return the address holding the next breakpoint line for a funccall cookie. | |
633 */ | |
634 linenr_T * | |
635 func_breakpoint(cookie) | |
636 void *cookie; | |
637 { | |
638 return &((funccall_T *)cookie)->breakpoint; | |
639 } | |
640 | |
641 /* | |
642 * Return the address holding the debug tick for a funccall cookie. | |
643 */ | |
644 int * | |
645 func_dbg_tick(cookie) | |
646 void *cookie; | |
647 { | |
648 return &((funccall_T *)cookie)->dbg_tick; | |
649 } | |
650 | |
651 /* | |
652 * Return the nesting level for a funccall cookie. | |
653 */ | |
654 int | |
655 func_level(cookie) | |
656 void *cookie; | |
657 { | |
658 return ((funccall_T *)cookie)->level; | |
659 } | |
660 | |
661 /* pointer to funccal for currently active function */ | |
662 funccall_T *current_funccal = NULL; | |
663 | |
664 /* | |
665 * Return TRUE when a function was ended by a ":return" command. | |
666 */ | |
667 int | |
668 current_func_returned() | |
669 { | |
670 return current_funccal->returned; | |
671 } | |
672 | |
727 | 673 |
728 /* | 674 /* |
729 * Set an internal variable to a string value. Creates the variable if it does | 675 * Set an internal variable to a string value. Creates the variable if it does |
730 * not already exist. | 676 * not already exist. |
731 */ | 677 */ |
733 set_internal_string_var(name, value) | 679 set_internal_string_var(name, value) |
734 char_u *name; | 680 char_u *name; |
735 char_u *value; | 681 char_u *value; |
736 { | 682 { |
737 char_u *val; | 683 char_u *val; |
738 typeval *tvp; | 684 typval_T *tvp; |
739 | 685 |
740 val = vim_strsave(value); | 686 val = vim_strsave(value); |
741 if (val != NULL) | 687 if (val != NULL) |
742 { | 688 { |
743 tvp = alloc_string_tv(val); | 689 tvp = alloc_string_tv(val); |
846 char_u *arg; | 792 char_u *arg; |
847 int *error; | 793 int *error; |
848 char_u **nextcmd; | 794 char_u **nextcmd; |
849 int skip; /* only parse, don't execute */ | 795 int skip; /* only parse, don't execute */ |
850 { | 796 { |
851 typeval tv; | 797 typval_T tv; |
852 int retval = FALSE; | 798 int retval = FALSE; |
853 | 799 |
854 if (skip) | 800 if (skip) |
855 ++emsg_skip; | 801 ++emsg_skip; |
856 if (eval0(arg, &tv, nextcmd, !skip) == FAIL) | 802 if (eval0(arg, &tv, nextcmd, !skip) == FAIL) |
879 eval_to_string_skip(arg, nextcmd, skip) | 825 eval_to_string_skip(arg, nextcmd, skip) |
880 char_u *arg; | 826 char_u *arg; |
881 char_u **nextcmd; | 827 char_u **nextcmd; |
882 int skip; /* only parse, don't execute */ | 828 int skip; /* only parse, don't execute */ |
883 { | 829 { |
884 typeval tv; | 830 typval_T tv; |
885 char_u *retval; | 831 char_u *retval; |
886 | 832 |
887 if (skip) | 833 if (skip) |
888 ++emsg_skip; | 834 ++emsg_skip; |
889 if (eval0(arg, &tv, nextcmd, !skip) == FAIL || skip) | 835 if (eval0(arg, &tv, nextcmd, !skip) == FAIL || skip) |
905 */ | 851 */ |
906 int | 852 int |
907 skip_expr(pp) | 853 skip_expr(pp) |
908 char_u **pp; | 854 char_u **pp; |
909 { | 855 { |
910 typeval rettv; | 856 typval_T rettv; |
911 | 857 |
912 *pp = skipwhite(*pp); | 858 *pp = skipwhite(*pp); |
913 return eval1(pp, &rettv, FALSE); | 859 return eval1(pp, &rettv, FALSE); |
914 } | 860 } |
915 | 861 |
920 char_u * | 866 char_u * |
921 eval_to_string(arg, nextcmd) | 867 eval_to_string(arg, nextcmd) |
922 char_u *arg; | 868 char_u *arg; |
923 char_u **nextcmd; | 869 char_u **nextcmd; |
924 { | 870 { |
925 typeval tv; | 871 typval_T tv; |
926 char_u *retval; | 872 char_u *retval; |
927 | 873 |
928 if (eval0(arg, &tv, nextcmd, TRUE) == FAIL) | 874 if (eval0(arg, &tv, nextcmd, TRUE) == FAIL) |
929 retval = NULL; | 875 retval = NULL; |
930 else | 876 else |
953 --sandbox; | 899 --sandbox; |
954 restore_funccal(save_funccalp); | 900 restore_funccal(save_funccalp); |
955 return retval; | 901 return retval; |
956 } | 902 } |
957 | 903 |
958 #if 0 /* not used */ | |
959 /* | |
960 * Top level evaluation function, returning a string. | |
961 * Advances "arg" to the first non-blank after the evaluated expression. | |
962 * Return pointer to allocated memory, or NULL for failure. | |
963 * Doesn't give error messages. | |
964 */ | |
965 char_u * | |
966 eval_arg_to_string(arg) | |
967 char_u **arg; | |
968 { | |
969 typeval rettv; | |
970 char_u *retval; | |
971 int ret; | |
972 | |
973 ++emsg_off; | |
974 | |
975 ret = eval1(arg, &rettv, TRUE); | |
976 if (ret == FAIL) | |
977 retval = NULL; | |
978 else | |
979 { | |
980 retval = vim_strsave(get_tv_string(&rettv)); | |
981 clear_tv(&rettv); | |
982 } | |
983 | |
984 --emsg_off; | |
985 | |
986 return retval; | |
987 } | |
988 #endif | |
989 | |
990 /* | 904 /* |
991 * Top level evaluation function, returning a number. | 905 * Top level evaluation function, returning a number. |
992 * Evaluates "expr" silently. | 906 * Evaluates "expr" silently. |
993 * Returns -1 for an error. | 907 * Returns -1 for an error. |
994 */ | 908 */ |
995 int | 909 int |
996 eval_to_number(expr) | 910 eval_to_number(expr) |
997 char_u *expr; | 911 char_u *expr; |
998 { | 912 { |
999 typeval rettv; | 913 typval_T rettv; |
1000 int retval; | 914 int retval; |
1001 char_u *p = skipwhite(expr); | 915 char_u *p = skipwhite(expr); |
1002 | 916 |
1003 ++emsg_off; | 917 ++emsg_off; |
1004 | 918 |
1025 int argc; | 939 int argc; |
1026 char_u **argv; | 940 char_u **argv; |
1027 int safe; /* use the sandbox */ | 941 int safe; /* use the sandbox */ |
1028 { | 942 { |
1029 char_u *retval = NULL; | 943 char_u *retval = NULL; |
1030 typeval rettv; | 944 typval_T rettv; |
1031 typeval *argvars; | 945 typval_T *argvars; |
1032 long n; | 946 long n; |
1033 int len; | 947 int len; |
1034 int i; | 948 int i; |
1035 int doesrange; | 949 int doesrange; |
1036 void *save_funccalp = NULL; | 950 void *save_funccalp = NULL; |
1037 | 951 |
1038 argvars = (typeval *)alloc((unsigned)(argc * sizeof(typeval))); | 952 argvars = (typval_T *)alloc((unsigned)(argc * sizeof(typval_T))); |
1039 if (argvars == NULL) | 953 if (argvars == NULL) |
1040 return NULL; | 954 return NULL; |
1041 | 955 |
1042 for (i = 0; i < argc; i++) | 956 for (i = 0; i < argc; i++) |
1043 { | 957 { |
1092 * Used when executing autocommands and for ":source". | 1006 * Used when executing autocommands and for ":source". |
1093 */ | 1007 */ |
1094 void * | 1008 void * |
1095 save_funccal() | 1009 save_funccal() |
1096 { | 1010 { |
1097 struct funccall *fc; | 1011 funccall_T *fc; |
1098 | 1012 |
1099 fc = current_funccal; | 1013 fc = current_funccal; |
1100 current_funccal = NULL; | 1014 current_funccal = NULL; |
1101 return (void *)fc; | 1015 return (void *)fc; |
1102 } | 1016 } |
1103 | 1017 |
1104 void | 1018 void |
1105 restore_funccal(fc) | 1019 restore_funccal(fc) |
1106 void *fc; | 1020 void *fc; |
1107 { | 1021 { |
1108 current_funccal = (struct funccall *)fc; | 1022 current_funccal = (funccall_T *)fc; |
1109 } | 1023 } |
1110 | 1024 |
1111 #ifdef FEAT_FOLDING | 1025 #ifdef FEAT_FOLDING |
1112 /* | 1026 /* |
1113 * Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding | 1027 * Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding |
1116 int | 1030 int |
1117 eval_foldexpr(arg, cp) | 1031 eval_foldexpr(arg, cp) |
1118 char_u *arg; | 1032 char_u *arg; |
1119 int *cp; | 1033 int *cp; |
1120 { | 1034 { |
1121 typeval tv; | 1035 typval_T tv; |
1122 int retval; | 1036 int retval; |
1123 char_u *s; | 1037 char_u *s; |
1124 | 1038 |
1125 ++emsg_off; | 1039 ++emsg_off; |
1126 ++sandbox; | 1040 ++sandbox; |
1234 ex_let(eap) | 1148 ex_let(eap) |
1235 exarg_T *eap; | 1149 exarg_T *eap; |
1236 { | 1150 { |
1237 char_u *arg = eap->arg; | 1151 char_u *arg = eap->arg; |
1238 char_u *expr = NULL; | 1152 char_u *expr = NULL; |
1239 typeval rettv; | 1153 typval_T rettv; |
1240 int i; | 1154 int i; |
1241 int var_count = 0; | 1155 int var_count = 0; |
1242 int semicolon = 0; | 1156 int semicolon = 0; |
1243 char_u op[2]; | 1157 char_u op[2]; |
1244 | 1158 |
1301 * Returns OK or FAIL; | 1215 * Returns OK or FAIL; |
1302 */ | 1216 */ |
1303 static int | 1217 static int |
1304 ex_let_vars(arg_start, tv, copy, semicolon, var_count, nextchars) | 1218 ex_let_vars(arg_start, tv, copy, semicolon, var_count, nextchars) |
1305 char_u *arg_start; | 1219 char_u *arg_start; |
1306 typeval *tv; | 1220 typval_T *tv; |
1307 int copy; /* copy values from "tv", don't move */ | 1221 int copy; /* copy values from "tv", don't move */ |
1308 int semicolon; /* from skip_var_list() */ | 1222 int semicolon; /* from skip_var_list() */ |
1309 int var_count; /* from skip_var_list() */ | 1223 int var_count; /* from skip_var_list() */ |
1310 char_u *nextchars; | 1224 char_u *nextchars; |
1311 { | 1225 { |
1312 char_u *arg = arg_start; | 1226 char_u *arg = arg_start; |
1313 listvar *l; | 1227 list_T *l; |
1314 int i; | 1228 int i; |
1315 listitem *item; | 1229 listitem_T *item; |
1316 typeval ltv; | 1230 typval_T ltv; |
1317 | 1231 |
1318 if (*arg != '[') | 1232 if (*arg != '[') |
1319 { | 1233 { |
1320 /* | 1234 /* |
1321 * ":let var = expr" or ":for var in list" | 1235 * ":let var = expr" or ":for var in list" |
1453 ++arg; | 1367 ++arg; |
1454 return find_name_end(arg, NULL, NULL, TRUE); | 1368 return find_name_end(arg, NULL, NULL, TRUE); |
1455 } | 1369 } |
1456 | 1370 |
1457 /* | 1371 /* |
1458 * List variables for hashtable "ht" with prefix "prefix". | 1372 * List variables for hashtab "ht" with prefix "prefix". |
1459 */ | 1373 * If "empty" is TRUE also list NULL strings as empty strings. |
1460 static void | 1374 */ |
1461 list_hashtable_vars(ht, prefix) | 1375 static void |
1462 hashtable *ht; | 1376 list_hashtable_vars(ht, prefix, empty) |
1377 hashtab_T *ht; | |
1463 char_u *prefix; | 1378 char_u *prefix; |
1464 { | 1379 int empty; |
1465 hashitem *hi; | 1380 { |
1381 hashitem_T *hi; | |
1382 dictitem_T *di; | |
1466 int todo; | 1383 int todo; |
1467 | 1384 |
1468 todo = ht->ht_used; | 1385 todo = ht->ht_used; |
1469 for (hi = ht->ht_array; todo > 0 && !got_int; ++hi) | 1386 for (hi = ht->ht_array; todo > 0 && !got_int; ++hi) |
1470 { | 1387 { |
1471 if (!HASHITEM_EMPTY(hi)) | 1388 if (!HASHITEM_EMPTY(hi)) |
1472 { | 1389 { |
1473 --todo; | 1390 --todo; |
1474 list_one_var(HI2VAR(hi), prefix); | 1391 di = HI2DI(hi); |
1392 if (empty || di->di_tv.v_type != VAR_STRING | |
1393 || di->di_tv.vval.v_string != NULL) | |
1394 list_one_var(di, prefix); | |
1475 } | 1395 } |
1476 } | 1396 } |
1477 } | 1397 } |
1478 | 1398 |
1479 /* | 1399 /* |
1480 * List global variables. | 1400 * List global variables. |
1481 */ | 1401 */ |
1482 static void | 1402 static void |
1483 list_glob_vars() | 1403 list_glob_vars() |
1484 { | 1404 { |
1485 list_hashtable_vars(&variables, (char_u *)""); | 1405 list_hashtable_vars(&globvarht, (char_u *)"", TRUE); |
1486 } | 1406 } |
1487 | 1407 |
1488 /* | 1408 /* |
1489 * List buffer variables. | 1409 * List buffer variables. |
1490 */ | 1410 */ |
1491 static void | 1411 static void |
1492 list_buf_vars() | 1412 list_buf_vars() |
1493 { | 1413 { |
1494 list_hashtable_vars(&curbuf->b_vars, (char_u *)"b:"); | 1414 list_hashtable_vars(&curbuf->b_vars.dv_hashtab, (char_u *)"b:", TRUE); |
1495 } | 1415 } |
1496 | 1416 |
1497 /* | 1417 /* |
1498 * List window variables. | 1418 * List window variables. |
1499 */ | 1419 */ |
1500 static void | 1420 static void |
1501 list_win_vars() | 1421 list_win_vars() |
1502 { | 1422 { |
1503 list_hashtable_vars(&curwin->w_vars, (char_u *)"w:"); | 1423 list_hashtable_vars(&curwin->w_vars.dv_hashtab, (char_u *)"w:", TRUE); |
1504 } | 1424 } |
1505 | 1425 |
1506 /* | 1426 /* |
1507 * List Vim variables. | 1427 * List Vim variables. |
1508 */ | 1428 */ |
1509 static void | 1429 static void |
1510 list_vim_vars() | 1430 list_vim_vars() |
1511 { | 1431 { |
1512 int i; | 1432 list_hashtable_vars(&vimvarht, (char_u *)"v:", FALSE); |
1513 | |
1514 for (i = 0; i < VV_LEN && !got_int; ++i) | |
1515 if (vimvars[i].tv.v_type == VAR_NUMBER || vimvars[i].vv_str != NULL) | |
1516 list_vim_var(i); | |
1517 } | 1433 } |
1518 | 1434 |
1519 /* | 1435 /* |
1520 * List variables in "arg". | 1436 * List variables in "arg". |
1521 */ | 1437 */ |
1529 int arg_len; | 1445 int arg_len; |
1530 char_u *expr_start; | 1446 char_u *expr_start; |
1531 char_u *expr_end; | 1447 char_u *expr_end; |
1532 char_u *name_end; | 1448 char_u *name_end; |
1533 int c1 = 0, c2; | 1449 int c1 = 0, c2; |
1534 int i; | 1450 dictitem_T *varp; |
1535 VAR varp; | |
1536 char_u *name; | 1451 char_u *name; |
1537 | 1452 |
1538 while (!ends_excmd(*arg) && !got_int) | 1453 while (!ends_excmd(*arg) && !got_int) |
1539 { | 1454 { |
1540 /* Find the end of the name. */ | 1455 /* Find the end of the name. */ |
1591 EMSG2(_("E738: Can't list variables for %s"), arg); | 1506 EMSG2(_("E738: Can't list variables for %s"), arg); |
1592 } | 1507 } |
1593 } | 1508 } |
1594 else | 1509 else |
1595 { | 1510 { |
1596 i = find_vim_var(arg, arg_len); | 1511 if (STRCMP("b:changedtick", arg) == 0) |
1597 if (i >= 0) | |
1598 list_vim_var(i); | |
1599 else if (STRCMP("b:changedtick", arg) == 0) | |
1600 { | 1512 { |
1601 char_u numbuf[NUMBUFLEN]; | 1513 char_u numbuf[NUMBUFLEN]; |
1602 | 1514 |
1603 sprintf((char *)numbuf, "%ld", | 1515 sprintf((char *)numbuf, "%ld", |
1604 (long)curbuf->b_changedtick); | 1516 (long)curbuf->b_changedtick); |
1654 * Returns NULL if there is an error. | 1566 * Returns NULL if there is an error. |
1655 */ | 1567 */ |
1656 static char_u * | 1568 static char_u * |
1657 ex_let_one(arg, tv, copy, endchars, op) | 1569 ex_let_one(arg, tv, copy, endchars, op) |
1658 char_u *arg; /* points to variable name */ | 1570 char_u *arg; /* points to variable name */ |
1659 typeval *tv; /* value to assign to variable */ | 1571 typval_T *tv; /* value to assign to variable */ |
1660 int copy; /* copy value from "tv" */ | 1572 int copy; /* copy value from "tv" */ |
1661 char_u *endchars; /* valid chars after variable name or NULL */ | 1573 char_u *endchars; /* valid chars after variable name or NULL */ |
1662 char_u *op; /* "+", "-", "." or NULL*/ | 1574 char_u *op; /* "+", "-", "." or NULL*/ |
1663 { | 1575 { |
1664 int c1; | 1576 int c1; |
1812 * ":let var = expr": Set internal variable. | 1724 * ":let var = expr": Set internal variable. |
1813 * ":let {expr} = expr": Idem, name made with curly braces | 1725 * ":let {expr} = expr": Idem, name made with curly braces |
1814 */ | 1726 */ |
1815 else if ((eval_isnamec(*arg) && !VIM_ISDIGIT(*arg)) || *arg == '{') | 1727 else if ((eval_isnamec(*arg) && !VIM_ISDIGIT(*arg)) || *arg == '{') |
1816 { | 1728 { |
1817 lval lv; | 1729 lval_T lv; |
1818 | 1730 |
1819 p = get_lval(arg, tv, &lv, FALSE, FALSE, FALSE); | 1731 p = get_lval(arg, tv, &lv, FALSE, FALSE, FALSE); |
1820 if (p != NULL && lv.ll_name != NULL) | 1732 if (p != NULL && lv.ll_name != NULL) |
1821 { | 1733 { |
1822 if (endchars != NULL && vim_strchr(endchars, *skipwhite(p)) == NULL) | 1734 if (endchars != NULL && vim_strchr(endchars, *skipwhite(p)) == NULL) |
1866 * Returns NULL for a parsing error. Still need to free items in "lp"! | 1778 * Returns NULL for a parsing error. Still need to free items in "lp"! |
1867 */ | 1779 */ |
1868 static char_u * | 1780 static char_u * |
1869 get_lval(name, rettv, lp, unlet, skip, quiet) | 1781 get_lval(name, rettv, lp, unlet, skip, quiet) |
1870 char_u *name; | 1782 char_u *name; |
1871 typeval *rettv; | 1783 typval_T *rettv; |
1872 lval *lp; | 1784 lval_T *lp; |
1873 int unlet; | 1785 int unlet; |
1874 int skip; | 1786 int skip; |
1875 int quiet; /* don't give error messages */ | 1787 int quiet; /* don't give error messages */ |
1876 { | 1788 { |
1877 char_u *p; | 1789 char_u *p; |
1878 char_u *expr_start, *expr_end; | 1790 char_u *expr_start, *expr_end; |
1879 int cc; | 1791 int cc; |
1880 VAR v; | 1792 dictitem_T *v; |
1881 typeval var1; | 1793 typval_T var1; |
1882 typeval var2; | 1794 typval_T var2; |
1883 int empty1 = FALSE; | 1795 int empty1 = FALSE; |
1884 listitem *ni; | 1796 listitem_T *ni; |
1885 char_u *key = NULL; | 1797 char_u *key = NULL; |
1886 int len; | 1798 int len; |
1887 hashtable *ht; | 1799 hashtab_T *ht; |
1888 | 1800 |
1889 /* Clear everything in "lp". */ | 1801 /* Clear everything in "lp". */ |
1890 vim_memset(lp, 0, sizeof(lval)); | 1802 vim_memset(lp, 0, sizeof(lval_T)); |
1891 | 1803 |
1892 if (skip) | 1804 if (skip) |
1893 { | 1805 { |
1894 /* When skipping just find the end of the name. */ | 1806 /* When skipping just find the end of the name. */ |
1895 lp->ll_name = name; | 1807 lp->ll_name = name; |
1940 return NULL; | 1852 return NULL; |
1941 | 1853 |
1942 /* | 1854 /* |
1943 * Loop until no more [idx] or .key is following. | 1855 * Loop until no more [idx] or .key is following. |
1944 */ | 1856 */ |
1945 lp->ll_tv = &v->tv; | 1857 lp->ll_tv = &v->di_tv; |
1946 while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT)) | 1858 while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT)) |
1947 { | 1859 { |
1948 if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL) | 1860 if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL) |
1949 && !(lp->ll_tv->v_type == VAR_DICT | 1861 && !(lp->ll_tv->v_type == VAR_DICT |
1950 && lp->ll_tv->vval.v_dict != NULL)) | 1862 && lp->ll_tv->vval.v_dict != NULL)) |
2145 | 2057 |
2146 return p; | 2058 return p; |
2147 } | 2059 } |
2148 | 2060 |
2149 /* | 2061 /* |
2150 * Clear an "lval" that was filled by get_lval(). | 2062 * Clear lval "lp" that was filled by get_lval(). |
2151 */ | 2063 */ |
2152 static void | 2064 static void |
2153 clear_lval(lp) | 2065 clear_lval(lp) |
2154 lval *lp; | 2066 lval_T *lp; |
2155 { | 2067 { |
2156 vim_free(lp->ll_exp_name); | 2068 vim_free(lp->ll_exp_name); |
2157 vim_free(lp->ll_newkey); | 2069 vim_free(lp->ll_newkey); |
2158 } | 2070 } |
2159 | 2071 |
2162 * "endp" points to just after the parsed name. | 2074 * "endp" points to just after the parsed name. |
2163 * "op" is NULL, "+" for "+=", "-" for "-=", "." for ".=" or "=" for "=". | 2075 * "op" is NULL, "+" for "+=", "-" for "-=", "." for ".=" or "=" for "=". |
2164 */ | 2076 */ |
2165 static void | 2077 static void |
2166 set_var_lval(lp, endp, rettv, copy, op) | 2078 set_var_lval(lp, endp, rettv, copy, op) |
2167 lval *lp; | 2079 lval_T *lp; |
2168 char_u *endp; | 2080 char_u *endp; |
2169 typeval *rettv; | 2081 typval_T *rettv; |
2170 int copy; | 2082 int copy; |
2171 char_u *op; | 2083 char_u *op; |
2172 { | 2084 { |
2173 int cc; | 2085 int cc; |
2174 listitem *ni; | 2086 listitem_T *ni; |
2175 listitem *ri; | 2087 listitem_T *ri; |
2176 dictitem *di; | 2088 dictitem_T *di; |
2177 | 2089 |
2178 if (lp->ll_tv == NULL) | 2090 if (lp->ll_tv == NULL) |
2179 { | 2091 { |
2180 if (!check_changedtick(lp->ll_name)) | 2092 if (!check_changedtick(lp->ll_name)) |
2181 { | 2093 { |
2182 cc = *endp; | 2094 cc = *endp; |
2183 *endp = NUL; | 2095 *endp = NUL; |
2184 if (op != NULL && *op != '=') | 2096 if (op != NULL && *op != '=') |
2185 { | 2097 { |
2186 typeval tv; | 2098 typval_T tv; |
2187 | 2099 |
2188 if (get_var_tv(lp->ll_name, STRLEN(lp->ll_name), &tv) == OK) | 2100 if (get_var_tv(lp->ll_name, STRLEN(lp->ll_name), &tv) == OK) |
2189 { | 2101 { |
2190 if (tv_op(&tv, rettv, op) == OK) | 2102 if (tv_op(&tv, rettv, op) == OK) |
2191 set_var(lp->ll_name, &tv, FALSE); | 2103 set_var(lp->ll_name, &tv, FALSE); |
2286 * Handle "tv1 += tv2", "tv1 -= tv2" and "tv1 .= tv2" | 2198 * Handle "tv1 += tv2", "tv1 -= tv2" and "tv1 .= tv2" |
2287 * Returns OK or FAIL. | 2199 * Returns OK or FAIL. |
2288 */ | 2200 */ |
2289 static int | 2201 static int |
2290 tv_op(tv1, tv2, op) | 2202 tv_op(tv1, tv2, op) |
2291 typeval *tv1; | 2203 typval_T *tv1; |
2292 typeval *tv2; | 2204 typval_T *tv2; |
2293 char_u *op; | 2205 char_u *op; |
2294 { | 2206 { |
2295 long n; | 2207 long n; |
2296 char_u numbuf[NUMBUFLEN]; | 2208 char_u numbuf[NUMBUFLEN]; |
2297 char_u *s; | 2209 char_u *s; |
2349 /* | 2261 /* |
2350 * Add a watcher to a list. | 2262 * Add a watcher to a list. |
2351 */ | 2263 */ |
2352 static void | 2264 static void |
2353 list_add_watch(l, lw) | 2265 list_add_watch(l, lw) |
2354 listvar *l; | 2266 list_T *l; |
2355 listwatch *lw; | 2267 listwatch_T *lw; |
2356 { | 2268 { |
2357 lw->lw_next = l->lv_watch; | 2269 lw->lw_next = l->lv_watch; |
2358 l->lv_watch = lw; | 2270 l->lv_watch = lw; |
2359 } | 2271 } |
2360 | 2272 |
2362 * Remove a watches from a list. | 2274 * Remove a watches from a list. |
2363 * No warning when it isn't found... | 2275 * No warning when it isn't found... |
2364 */ | 2276 */ |
2365 static void | 2277 static void |
2366 list_rem_watch(l, lwrem) | 2278 list_rem_watch(l, lwrem) |
2367 listvar *l; | 2279 list_T *l; |
2368 listwatch *lwrem; | 2280 listwatch_T *lwrem; |
2369 { | 2281 { |
2370 listwatch *lw, **lwp; | 2282 listwatch_T *lw, **lwp; |
2371 | 2283 |
2372 lwp = &l->lv_watch; | 2284 lwp = &l->lv_watch; |
2373 for (lw = l->lv_watch; lw != NULL; lw = lw->lw_next) | 2285 for (lw = l->lv_watch; lw != NULL; lw = lw->lw_next) |
2374 { | 2286 { |
2375 if (lw == lwrem) | 2287 if (lw == lwrem) |
2385 * Just before removing an item from a list: advance watchers to the next | 2297 * Just before removing an item from a list: advance watchers to the next |
2386 * item. | 2298 * item. |
2387 */ | 2299 */ |
2388 static void | 2300 static void |
2389 list_fix_watch(l, item) | 2301 list_fix_watch(l, item) |
2390 listvar *l; | 2302 list_T *l; |
2391 listitem *item; | 2303 listitem_T *item; |
2392 { | 2304 { |
2393 listwatch *lw; | 2305 listwatch_T *lw; |
2394 | 2306 |
2395 for (lw = l->lv_watch; lw != NULL; lw = lw->lw_next) | 2307 for (lw = l->lv_watch; lw != NULL; lw = lw->lw_next) |
2396 if (lw->lw_item == item) | 2308 if (lw->lw_item == item) |
2397 lw->lw_item = item->li_next; | 2309 lw->lw_item = item->li_next; |
2398 } | 2310 } |
2408 char_u *arg; | 2320 char_u *arg; |
2409 int *errp; | 2321 int *errp; |
2410 char_u **nextcmdp; | 2322 char_u **nextcmdp; |
2411 int skip; | 2323 int skip; |
2412 { | 2324 { |
2413 forinfo *fi; | 2325 forinfo_T *fi; |
2414 char_u *expr; | 2326 char_u *expr; |
2415 typeval tv; | 2327 typval_T tv; |
2416 listvar *l; | 2328 list_T *l; |
2417 | 2329 |
2418 *errp = TRUE; /* default: there is an error */ | 2330 *errp = TRUE; /* default: there is an error */ |
2419 | 2331 |
2420 fi = (forinfo *)alloc_clear(sizeof(forinfo)); | 2332 fi = (forinfo_T *)alloc_clear(sizeof(forinfo_T)); |
2421 if (fi == NULL) | 2333 if (fi == NULL) |
2422 return NULL; | 2334 return NULL; |
2423 | 2335 |
2424 expr = skip_var_list(arg, &fi->fi_varcount, &fi->fi_semicolon); | 2336 expr = skip_var_list(arg, &fi->fi_varcount, &fi->fi_semicolon); |
2425 if (expr == NULL) | 2337 if (expr == NULL) |
2465 int | 2377 int |
2466 next_for_item(fi_void, arg) | 2378 next_for_item(fi_void, arg) |
2467 void *fi_void; | 2379 void *fi_void; |
2468 char_u *arg; | 2380 char_u *arg; |
2469 { | 2381 { |
2470 forinfo *fi = (forinfo *)fi_void; | 2382 forinfo_T *fi = (forinfo_T *)fi_void; |
2471 int result; | 2383 int result; |
2472 listitem *item; | 2384 listitem_T *item; |
2473 | 2385 |
2474 item = fi->fi_lw.lw_item; | 2386 item = fi->fi_lw.lw_item; |
2475 if (item == NULL) | 2387 if (item == NULL) |
2476 result = FALSE; | 2388 result = FALSE; |
2477 else | 2389 else |
2488 */ | 2400 */ |
2489 void | 2401 void |
2490 free_for_info(fi_void) | 2402 free_for_info(fi_void) |
2491 void *fi_void; | 2403 void *fi_void; |
2492 { | 2404 { |
2493 forinfo *fi = (forinfo *)fi_void; | 2405 forinfo_T *fi = (forinfo_T *)fi_void; |
2494 | 2406 |
2495 if (fi != NULL && fi->fi_list != NULL) | 2407 if (fi != NULL && fi->fi_list != NULL) |
2496 list_rem_watch(fi->fi_list, &fi->fi_lw); | 2408 list_rem_watch(fi->fi_list, &fi->fi_lw); |
2497 vim_free(fi); | 2409 vim_free(fi); |
2498 } | 2410 } |
2516 { | 2428 { |
2517 /* ":let var1 var2 ...": find last space. */ | 2429 /* ":let var1 var2 ...": find last space. */ |
2518 for (p = arg + STRLEN(arg); p > arg; ) | 2430 for (p = arg + STRLEN(arg); p > arg; ) |
2519 { | 2431 { |
2520 xp->xp_pattern = p; | 2432 xp->xp_pattern = p; |
2521 p = mb_ptr_back(arg, p); | 2433 mb_ptr_back(arg, p); |
2522 if (vim_iswhite(*p)) | 2434 if (vim_iswhite(*p)) |
2523 break; | 2435 break; |
2524 } | 2436 } |
2525 return; | 2437 return; |
2526 } | 2438 } |
2614 char_u *arg = eap->arg; | 2526 char_u *arg = eap->arg; |
2615 char_u *startarg; | 2527 char_u *startarg; |
2616 char_u *name; | 2528 char_u *name; |
2617 char_u *tofree; | 2529 char_u *tofree; |
2618 int len; | 2530 int len; |
2619 typeval rettv; | 2531 typval_T rettv; |
2620 linenr_T lnum; | 2532 linenr_T lnum; |
2621 int doesrange; | 2533 int doesrange; |
2622 int failed = FALSE; | 2534 int failed = FALSE; |
2623 funcdict fudi; | 2535 funcdict_T fudi; |
2624 | 2536 |
2625 tofree = trans_function_name(&arg, eap->skip, TFN_INT, &fudi); | 2537 tofree = trans_function_name(&arg, eap->skip, TFN_INT, &fudi); |
2626 vim_free(fudi.fd_newkey); | 2538 vim_free(fudi.fd_newkey); |
2627 if (tofree == NULL) | 2539 if (tofree == NULL) |
2628 return; | 2540 return; |
2714 char_u *name_end; | 2626 char_u *name_end; |
2715 int error = FALSE; | 2627 int error = FALSE; |
2716 | 2628 |
2717 do | 2629 do |
2718 { | 2630 { |
2719 lval lv; | 2631 lval_T lv; |
2720 | 2632 |
2721 /* Parse the name and find the end. */ | 2633 /* Parse the name and find the end. */ |
2722 name_end = get_lval(arg, NULL, &lv, TRUE, eap->skip || error, FALSE); | 2634 name_end = get_lval(arg, NULL, &lv, TRUE, eap->skip || error, FALSE); |
2723 if (lv.ll_name == NULL) | 2635 if (lv.ll_name == NULL) |
2724 error = TRUE; /* error but continue parsing */ | 2636 error = TRUE; /* error but continue parsing */ |
2749 } | 2661 } |
2750 | 2662 |
2751 | 2663 |
2752 static int | 2664 static int |
2753 do_unlet_var(lp, name_end, forceit) | 2665 do_unlet_var(lp, name_end, forceit) |
2754 lval *lp; | 2666 lval_T *lp; |
2755 char_u *name_end; | 2667 char_u *name_end; |
2756 int forceit; | 2668 int forceit; |
2757 { | 2669 { |
2758 int ret = OK; | 2670 int ret = OK; |
2759 int cc; | 2671 int cc; |
2773 } | 2685 } |
2774 *name_end = cc; | 2686 *name_end = cc; |
2775 } | 2687 } |
2776 else if (lp->ll_range) | 2688 else if (lp->ll_range) |
2777 { | 2689 { |
2778 listitem *li; | 2690 listitem_T *li; |
2779 | 2691 |
2780 /* Delete a range of List items. */ | 2692 /* Delete a range of List items. */ |
2781 while (lp->ll_li != NULL && (lp->ll_empty2 || lp->ll_n2 >= lp->ll_n1)) | 2693 while (lp->ll_li != NULL && (lp->ll_empty2 || lp->ll_n2 >= lp->ll_n1)) |
2782 { | 2694 { |
2783 li = lp->ll_li->li_next; | 2695 li = lp->ll_li->li_next; |
2804 */ | 2716 */ |
2805 int | 2717 int |
2806 do_unlet(name) | 2718 do_unlet(name) |
2807 char_u *name; | 2719 char_u *name; |
2808 { | 2720 { |
2809 hashtable *ht; | 2721 hashtab_T *ht; |
2810 hashitem *hi; | 2722 hashitem_T *hi; |
2811 char_u *varname; | 2723 char_u *varname; |
2812 | 2724 |
2813 if (name[0] == 'a' && name[1] == ':') | 2725 ht = find_var_ht(name, &varname); |
2814 EMSG2(_(e_readonlyvar), name); | 2726 if (ht != NULL && *varname != NUL) |
2815 else | 2727 { |
2816 { | 2728 hi = hash_find(ht, varname); |
2817 ht = find_var_ht(name, &varname); | 2729 if (!HASHITEM_EMPTY(hi)) |
2818 if (ht != NULL) | 2730 { |
2819 { | 2731 if (!var_check_ro(HI2DI(hi)->di_flags, name)) |
2820 hi = hash_find(ht, varname); | |
2821 if (!HASHITEM_EMPTY(hi)) | |
2822 { | 2732 { |
2823 delete_var(ht, hi); | 2733 delete_var(ht, hi); |
2824 return OK; | 2734 return OK; |
2825 } | 2735 } |
2826 } | 2736 } |
2833 * Delete all "menutrans_" variables. | 2743 * Delete all "menutrans_" variables. |
2834 */ | 2744 */ |
2835 void | 2745 void |
2836 del_menutrans_vars() | 2746 del_menutrans_vars() |
2837 { | 2747 { |
2838 hashitem *hi; | 2748 hashitem_T *hi; |
2839 int todo; | 2749 int todo; |
2840 | 2750 |
2841 hash_lock(&variables); | 2751 hash_lock(&globvarht); |
2842 todo = variables.ht_used; | 2752 todo = globvarht.ht_used; |
2843 for (hi = variables.ht_array; todo > 0 && !got_int; ++hi) | 2753 for (hi = globvarht.ht_array; todo > 0 && !got_int; ++hi) |
2844 { | 2754 { |
2845 if (!HASHITEM_EMPTY(hi)) | 2755 if (!HASHITEM_EMPTY(hi)) |
2846 { | 2756 { |
2847 --todo; | 2757 --todo; |
2848 if (STRNCMP(HI2VAR(hi)->v_name, "menutrans_", 10) == 0) | 2758 if (STRNCMP(HI2DI(hi)->di_key, "menutrans_", 10) == 0) |
2849 delete_var(&variables, hi); | 2759 delete_var(&globvarht, hi); |
2850 } | 2760 } |
2851 } | 2761 } |
2852 hash_unlock(&variables); | 2762 hash_unlock(&globvarht); |
2853 } | 2763 } |
2854 #endif | 2764 #endif |
2855 | 2765 |
2856 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | 2766 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
2857 | 2767 |
2907 { | 2817 { |
2908 static int gdone; | 2818 static int gdone; |
2909 static int bdone; | 2819 static int bdone; |
2910 static int wdone; | 2820 static int wdone; |
2911 static int vidx; | 2821 static int vidx; |
2912 static hashitem *hi; | 2822 static hashitem_T *hi; |
2823 hashtab_T *ht; | |
2913 | 2824 |
2914 if (idx == 0) | 2825 if (idx == 0) |
2915 gdone = bdone = wdone = vidx = 0; | 2826 gdone = bdone = wdone = vidx = 0; |
2916 if (gdone < variables.ht_used) /* Global variables */ | 2827 |
2828 /* Global variables */ | |
2829 if (gdone < globvarht.ht_used) | |
2917 { | 2830 { |
2918 if (gdone++ == 0) | 2831 if (gdone++ == 0) |
2919 hi = variables.ht_array; | 2832 hi = globvarht.ht_array; |
2920 while (HASHITEM_EMPTY(hi)) | 2833 while (HASHITEM_EMPTY(hi)) |
2921 ++hi; | 2834 ++hi; |
2922 if (STRNCMP("g:", xp->xp_pattern, 2) == 0) | 2835 if (STRNCMP("g:", xp->xp_pattern, 2) == 0) |
2923 return cat_prefix_varname('g', hi->hi_key); | 2836 return cat_prefix_varname('g', hi->hi_key); |
2924 return hi->hi_key; | 2837 return hi->hi_key; |
2925 } | 2838 } |
2926 if (bdone < curbuf->b_vars.ht_used) /* Current buffer variables */ | 2839 |
2840 /* b: variables */ | |
2841 ht = &curbuf->b_vars.dv_hashtab; | |
2842 if (bdone < ht->ht_used) | |
2927 { | 2843 { |
2928 if (bdone++ == 0) | 2844 if (bdone++ == 0) |
2929 hi = curbuf->b_vars.ht_array; | 2845 hi = ht->ht_array; |
2930 while (HASHITEM_EMPTY(hi)) | 2846 while (HASHITEM_EMPTY(hi)) |
2931 ++hi; | 2847 ++hi; |
2932 return cat_prefix_varname('b', hi->hi_key); | 2848 return cat_prefix_varname('b', hi->hi_key); |
2933 } | 2849 } |
2934 if (bdone == curbuf->b_vars.ht_used) | 2850 if (bdone == ht->ht_used) |
2935 { | 2851 { |
2936 ++bdone; | 2852 ++bdone; |
2937 return (char_u *)"b:changedtick"; | 2853 return (char_u *)"b:changedtick"; |
2938 } | 2854 } |
2939 if (wdone < curwin->w_vars.ht_used) /* Current window variables */ | 2855 |
2856 /* w: variables */ | |
2857 ht = &curwin->w_vars.dv_hashtab; | |
2858 if (wdone < ht->ht_used) | |
2940 { | 2859 { |
2941 if (bdone++ == 0) | 2860 if (bdone++ == 0) |
2942 hi = curwin->w_vars.ht_array; | 2861 hi = ht->ht_array; |
2943 while (HASHITEM_EMPTY(hi)) | 2862 while (HASHITEM_EMPTY(hi)) |
2944 ++hi; | 2863 ++hi; |
2945 return cat_prefix_varname('w', hi->hi_key); | 2864 return cat_prefix_varname('w', hi->hi_key); |
2946 } | 2865 } |
2947 if (vidx < VV_LEN) /* Built-in variables */ | 2866 |
2948 return cat_prefix_varname('v', (char_u *)vimvars[vidx++].name); | 2867 /* v: variables */ |
2868 if (vidx < VV_LEN) | |
2869 return cat_prefix_varname('v', (char_u *)vimvars[vidx++].vv_name); | |
2949 | 2870 |
2950 vim_free(varnamebuf); | 2871 vim_free(varnamebuf); |
2951 varnamebuf = NULL; | 2872 varnamebuf = NULL; |
2952 varnamebuflen = 0; | 2873 varnamebuflen = 0; |
2953 return NULL; | 2874 return NULL; |
2984 * Return OK or FAIL. | 2905 * Return OK or FAIL. |
2985 */ | 2906 */ |
2986 static int | 2907 static int |
2987 eval0(arg, rettv, nextcmd, evaluate) | 2908 eval0(arg, rettv, nextcmd, evaluate) |
2988 char_u *arg; | 2909 char_u *arg; |
2989 typeval *rettv; | 2910 typval_T *rettv; |
2990 char_u **nextcmd; | 2911 char_u **nextcmd; |
2991 int evaluate; | 2912 int evaluate; |
2992 { | 2913 { |
2993 int ret; | 2914 int ret; |
2994 char_u *p; | 2915 char_u *p; |
3024 * Return OK or FAIL. | 2945 * Return OK or FAIL. |
3025 */ | 2946 */ |
3026 static int | 2947 static int |
3027 eval1(arg, rettv, evaluate) | 2948 eval1(arg, rettv, evaluate) |
3028 char_u **arg; | 2949 char_u **arg; |
3029 typeval *rettv; | 2950 typval_T *rettv; |
3030 int evaluate; | 2951 int evaluate; |
3031 { | 2952 { |
3032 int result; | 2953 int result; |
3033 typeval var2; | 2954 typval_T var2; |
3034 | 2955 |
3035 /* | 2956 /* |
3036 * Get the first variable. | 2957 * Get the first variable. |
3037 */ | 2958 */ |
3038 if (eval2(arg, rettv, evaluate) == FAIL) | 2959 if (eval2(arg, rettv, evaluate) == FAIL) |
3093 * Return OK or FAIL. | 3014 * Return OK or FAIL. |
3094 */ | 3015 */ |
3095 static int | 3016 static int |
3096 eval2(arg, rettv, evaluate) | 3017 eval2(arg, rettv, evaluate) |
3097 char_u **arg; | 3018 char_u **arg; |
3098 typeval *rettv; | 3019 typval_T *rettv; |
3099 int evaluate; | 3020 int evaluate; |
3100 { | 3021 { |
3101 typeval var2; | 3022 typval_T var2; |
3102 long result; | 3023 long result; |
3103 int first; | 3024 int first; |
3104 | 3025 |
3105 /* | 3026 /* |
3106 * Get the first variable. | 3027 * Get the first variable. |
3159 * Return OK or FAIL. | 3080 * Return OK or FAIL. |
3160 */ | 3081 */ |
3161 static int | 3082 static int |
3162 eval3(arg, rettv, evaluate) | 3083 eval3(arg, rettv, evaluate) |
3163 char_u **arg; | 3084 char_u **arg; |
3164 typeval *rettv; | 3085 typval_T *rettv; |
3165 int evaluate; | 3086 int evaluate; |
3166 { | 3087 { |
3167 typeval var2; | 3088 typval_T var2; |
3168 long result; | 3089 long result; |
3169 int first; | 3090 int first; |
3170 | 3091 |
3171 /* | 3092 /* |
3172 * Get the first variable. | 3093 * Get the first variable. |
3234 * Return OK or FAIL. | 3155 * Return OK or FAIL. |
3235 */ | 3156 */ |
3236 static int | 3157 static int |
3237 eval4(arg, rettv, evaluate) | 3158 eval4(arg, rettv, evaluate) |
3238 char_u **arg; | 3159 char_u **arg; |
3239 typeval *rettv; | 3160 typval_T *rettv; |
3240 int evaluate; | 3161 int evaluate; |
3241 { | 3162 { |
3242 typeval var2; | 3163 typval_T var2; |
3243 char_u *p; | 3164 char_u *p; |
3244 int i; | 3165 int i; |
3245 exptype_T type = TYPE_UNKNOWN; | 3166 exptype_T type = TYPE_UNKNOWN; |
3246 int type_is = FALSE; /* TRUE for "is" and "isnot" */ | 3167 int type_is = FALSE; /* TRUE for "is" and "isnot" */ |
3247 int len = 2; | 3168 int len = 2; |
3507 * Return OK or FAIL. | 3428 * Return OK or FAIL. |
3508 */ | 3429 */ |
3509 static int | 3430 static int |
3510 eval5(arg, rettv, evaluate) | 3431 eval5(arg, rettv, evaluate) |
3511 char_u **arg; | 3432 char_u **arg; |
3512 typeval *rettv; | 3433 typval_T *rettv; |
3513 int evaluate; | 3434 int evaluate; |
3514 { | 3435 { |
3515 typeval var2; | 3436 typval_T var2; |
3516 typeval var3; | 3437 typval_T var3; |
3517 int op; | 3438 int op; |
3518 long n1, n2; | 3439 long n1, n2; |
3519 char_u *s1, *s2; | 3440 char_u *s1, *s2; |
3520 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; | 3441 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; |
3521 char_u *p; | 3442 char_u *p; |
3603 * Return OK or FAIL. | 3524 * Return OK or FAIL. |
3604 */ | 3525 */ |
3605 static int | 3526 static int |
3606 eval6(arg, rettv, evaluate) | 3527 eval6(arg, rettv, evaluate) |
3607 char_u **arg; | 3528 char_u **arg; |
3608 typeval *rettv; | 3529 typval_T *rettv; |
3609 int evaluate; | 3530 int evaluate; |
3610 { | 3531 { |
3611 typeval var2; | 3532 typval_T var2; |
3612 int op; | 3533 int op; |
3613 long n1, n2; | 3534 long n1, n2; |
3614 | 3535 |
3615 /* | 3536 /* |
3616 * Get the first variable. | 3537 * Get the first variable. |
3699 * Return OK or FAIL. | 3620 * Return OK or FAIL. |
3700 */ | 3621 */ |
3701 static int | 3622 static int |
3702 eval7(arg, rettv, evaluate) | 3623 eval7(arg, rettv, evaluate) |
3703 char_u **arg; | 3624 char_u **arg; |
3704 typeval *rettv; | 3625 typval_T *rettv; |
3705 int evaluate; | 3626 int evaluate; |
3706 { | 3627 { |
3707 long n; | 3628 long n; |
3708 int len; | 3629 int len; |
3709 char_u *s; | 3630 char_u *s; |
3710 int val; | 3631 int val; |
3711 char_u *start_leader, *end_leader; | 3632 char_u *start_leader, *end_leader; |
3712 int ret = OK; | 3633 int ret = OK; |
3713 char_u *alias; | 3634 char_u *alias; |
3714 dictvar *selfdict; | 3635 dict_T *selfdict; |
3715 | 3636 |
3716 /* | 3637 /* |
3717 * Initialise variable so that clear_tv() can't mistake this for a | 3638 * Initialise variable so that clear_tv() can't mistake this for a |
3718 * string and free a string that isn't there. | 3639 * string and free a string that isn't there. |
3719 */ | 3640 */ |
3947 * Returns FAIL or OK. "*arg" is advanced to after the ']'. | 3868 * Returns FAIL or OK. "*arg" is advanced to after the ']'. |
3948 */ | 3869 */ |
3949 static int | 3870 static int |
3950 eval_index(arg, rettv, evaluate) | 3871 eval_index(arg, rettv, evaluate) |
3951 char_u **arg; | 3872 char_u **arg; |
3952 typeval *rettv; | 3873 typval_T *rettv; |
3953 int evaluate; | 3874 int evaluate; |
3954 { | 3875 { |
3955 int empty1 = FALSE, empty2 = FALSE; | 3876 int empty1 = FALSE, empty2 = FALSE; |
3956 typeval var1, var2; | 3877 typval_T var1, var2; |
3957 long n1, n2 = 0; | 3878 long n1, n2 = 0; |
3958 long len = -1; | 3879 long len = -1; |
3959 int range = FALSE; | 3880 int range = FALSE; |
3960 char_u *s; | 3881 char_u *s; |
3961 char_u *key = NULL; | 3882 char_u *key = NULL; |
4087 EMSGN(_(e_listidx), n1); | 4008 EMSGN(_(e_listidx), n1); |
4088 return FAIL; | 4009 return FAIL; |
4089 } | 4010 } |
4090 if (range) | 4011 if (range) |
4091 { | 4012 { |
4092 listvar *l; | 4013 list_T *l; |
4093 listitem *item; | 4014 listitem_T *item; |
4094 | 4015 |
4095 if (n2 < 0) | 4016 if (n2 < 0) |
4096 n2 = len + n2; | 4017 n2 = len + n2; |
4097 if (!empty2 && (n2 < 0 || n2 >= len || n2 + 1 < n1)) | 4018 if (!empty2 && (n2 < 0 || n2 >= len || n2 + 1 < n1)) |
4098 { | 4019 { |
4133 if (len == -1) | 4054 if (len == -1) |
4134 clear_tv(&var1); | 4055 clear_tv(&var1); |
4135 return FAIL; | 4056 return FAIL; |
4136 } | 4057 } |
4137 { | 4058 { |
4138 dictitem *item; | 4059 dictitem_T *item; |
4139 | 4060 |
4140 if (len == -1) | 4061 if (len == -1) |
4141 { | 4062 { |
4142 key = get_tv_string(&var1); | 4063 key = get_tv_string(&var1); |
4143 if (*key == NUL) | 4064 if (*key == NUL) |
4175 * Return OK or FAIL. | 4096 * Return OK or FAIL. |
4176 */ | 4097 */ |
4177 static int | 4098 static int |
4178 get_option_tv(arg, rettv, evaluate) | 4099 get_option_tv(arg, rettv, evaluate) |
4179 char_u **arg; | 4100 char_u **arg; |
4180 typeval *rettv; /* when NULL, only check if option exists */ | 4101 typval_T *rettv; /* when NULL, only check if option exists */ |
4181 int evaluate; | 4102 int evaluate; |
4182 { | 4103 { |
4183 char_u *option_end; | 4104 char_u *option_end; |
4184 long numval; | 4105 long numval; |
4185 char_u *stringval; | 4106 char_u *stringval; |
4254 * Return OK or FAIL. | 4175 * Return OK or FAIL. |
4255 */ | 4176 */ |
4256 static int | 4177 static int |
4257 get_string_tv(arg, rettv, evaluate) | 4178 get_string_tv(arg, rettv, evaluate) |
4258 char_u **arg; | 4179 char_u **arg; |
4259 typeval *rettv; | 4180 typval_T *rettv; |
4260 int evaluate; | 4181 int evaluate; |
4261 { | 4182 { |
4262 char_u *p; | 4183 char_u *p; |
4263 char_u *name; | 4184 char_u *name; |
4264 int extra = 0; | 4185 int extra = 0; |
4391 * Return OK or FAIL. | 4312 * Return OK or FAIL. |
4392 */ | 4313 */ |
4393 static int | 4314 static int |
4394 get_lit_string_tv(arg, rettv, evaluate) | 4315 get_lit_string_tv(arg, rettv, evaluate) |
4395 char_u **arg; | 4316 char_u **arg; |
4396 typeval *rettv; | 4317 typval_T *rettv; |
4397 int evaluate; | 4318 int evaluate; |
4398 { | 4319 { |
4399 char_u *p; | 4320 char_u *p; |
4400 char_u *str; | 4321 char_u *str; |
4401 int reduce = 0; | 4322 int reduce = 0; |
4457 * Return OK or FAIL. | 4378 * Return OK or FAIL. |
4458 */ | 4379 */ |
4459 static int | 4380 static int |
4460 get_list_tv(arg, rettv, evaluate) | 4381 get_list_tv(arg, rettv, evaluate) |
4461 char_u **arg; | 4382 char_u **arg; |
4462 typeval *rettv; | 4383 typval_T *rettv; |
4463 int evaluate; | 4384 int evaluate; |
4464 { | 4385 { |
4465 listvar *l = NULL; | 4386 list_T *l = NULL; |
4466 typeval tv; | 4387 typval_T tv; |
4467 listitem *item; | 4388 listitem_T *item; |
4468 | 4389 |
4469 if (evaluate) | 4390 if (evaluate) |
4470 { | 4391 { |
4471 l = list_alloc(); | 4392 l = list_alloc(); |
4472 if (l == NULL) | 4393 if (l == NULL) |
4521 } | 4442 } |
4522 | 4443 |
4523 /* | 4444 /* |
4524 * Allocate an empty header for a list. | 4445 * Allocate an empty header for a list. |
4525 */ | 4446 */ |
4526 static listvar * | 4447 static list_T * |
4527 list_alloc() | 4448 list_alloc() |
4528 { | 4449 { |
4529 return (listvar *)alloc_clear(sizeof(listvar)); | 4450 return (list_T *)alloc_clear(sizeof(list_T)); |
4530 } | 4451 } |
4531 | 4452 |
4532 /* | 4453 /* |
4533 * Unreference a list: decrement the reference count and free it when it | 4454 * Unreference a list: decrement the reference count and free it when it |
4534 * becomes zero. | 4455 * becomes zero. |
4535 */ | 4456 */ |
4536 static void | 4457 static void |
4537 list_unref(l) | 4458 list_unref(l) |
4538 listvar *l; | 4459 list_T *l; |
4539 { | 4460 { |
4540 if (l != NULL && --l->lv_refcount <= 0) | 4461 if (l != NULL && --l->lv_refcount <= 0) |
4541 list_free(l); | 4462 list_free(l); |
4542 } | 4463 } |
4543 | 4464 |
4545 * Free a list, including all items it points to. | 4466 * Free a list, including all items it points to. |
4546 * Ignores the reference count. | 4467 * Ignores the reference count. |
4547 */ | 4468 */ |
4548 static void | 4469 static void |
4549 list_free(l) | 4470 list_free(l) |
4550 listvar *l; | 4471 list_T *l; |
4551 { | 4472 { |
4552 listitem *item; | 4473 listitem_T *item; |
4553 listitem *next; | 4474 listitem_T *next; |
4554 | 4475 |
4555 for (item = l->lv_first; item != NULL; item = next) | 4476 for (item = l->lv_first; item != NULL; item = next) |
4556 { | 4477 { |
4557 next = item->li_next; | 4478 next = item->li_next; |
4558 listitem_free(item); | 4479 listitem_free(item); |
4561 } | 4482 } |
4562 | 4483 |
4563 /* | 4484 /* |
4564 * Allocate a list item. | 4485 * Allocate a list item. |
4565 */ | 4486 */ |
4566 static listitem * | 4487 static listitem_T * |
4567 listitem_alloc() | 4488 listitem_alloc() |
4568 { | 4489 { |
4569 return (listitem *)alloc(sizeof(listitem)); | 4490 return (listitem_T *)alloc(sizeof(listitem_T)); |
4570 } | 4491 } |
4571 | 4492 |
4572 /* | 4493 /* |
4573 * Free a list item. Also clears the value. Does not notify watchers. | 4494 * Free a list item. Also clears the value. Does not notify watchers. |
4574 */ | 4495 */ |
4575 static void | 4496 static void |
4576 listitem_free(item) | 4497 listitem_free(item) |
4577 listitem *item; | 4498 listitem_T *item; |
4578 { | 4499 { |
4579 clear_tv(&item->li_tv); | 4500 clear_tv(&item->li_tv); |
4580 vim_free(item); | 4501 vim_free(item); |
4581 } | 4502 } |
4582 | 4503 |
4583 /* | 4504 /* |
4584 * Remove a list item from a List and free it. Also clears the value. | 4505 * Remove a list item from a List and free it. Also clears the value. |
4585 */ | 4506 */ |
4586 static void | 4507 static void |
4587 listitem_remove(l, item) | 4508 listitem_remove(l, item) |
4588 listvar *l; | 4509 list_T *l; |
4589 listitem *item; | 4510 listitem_T *item; |
4590 { | 4511 { |
4591 list_remove(l, item, item); | 4512 list_remove(l, item, item); |
4592 listitem_free(item); | 4513 listitem_free(item); |
4593 } | 4514 } |
4594 | 4515 |
4595 /* | 4516 /* |
4596 * Get the number of items in a list. | 4517 * Get the number of items in a list. |
4597 */ | 4518 */ |
4598 static long | 4519 static long |
4599 list_len(l) | 4520 list_len(l) |
4600 listvar *l; | 4521 list_T *l; |
4601 { | 4522 { |
4602 listitem *item; | 4523 listitem_T *item; |
4603 long len = 0; | 4524 long len = 0; |
4604 | 4525 |
4605 if (l == NULL) | 4526 if (l == NULL) |
4606 return 0L; | 4527 return 0L; |
4607 for (item = l->lv_first; item != NULL; item = item->li_next) | 4528 for (item = l->lv_first; item != NULL; item = item->li_next) |
4612 /* | 4533 /* |
4613 * Return TRUE when two lists have exactly the same values. | 4534 * Return TRUE when two lists have exactly the same values. |
4614 */ | 4535 */ |
4615 static int | 4536 static int |
4616 list_equal(l1, l2, ic) | 4537 list_equal(l1, l2, ic) |
4617 listvar *l1; | 4538 list_T *l1; |
4618 listvar *l2; | 4539 list_T *l2; |
4619 int ic; /* ignore case for strings */ | 4540 int ic; /* ignore case for strings */ |
4620 { | 4541 { |
4621 listitem *item1, *item2; | 4542 listitem_T *item1, *item2; |
4622 | 4543 |
4623 if (list_len(l1) != list_len(l2)) | 4544 if (list_len(l1) != list_len(l2)) |
4624 return FALSE; | 4545 return FALSE; |
4625 | 4546 |
4626 for (item1 = l1->lv_first, item2 = l2->lv_first; | 4547 for (item1 = l1->lv_first, item2 = l2->lv_first; |
4634 /* | 4555 /* |
4635 * Return TRUE when two dictionaries have exactly the same key/values. | 4556 * Return TRUE when two dictionaries have exactly the same key/values. |
4636 */ | 4557 */ |
4637 static int | 4558 static int |
4638 dict_equal(d1, d2, ic) | 4559 dict_equal(d1, d2, ic) |
4639 dictvar *d1; | 4560 dict_T *d1; |
4640 dictvar *d2; | 4561 dict_T *d2; |
4641 int ic; /* ignore case for strings */ | 4562 int ic; /* ignore case for strings */ |
4642 { | 4563 { |
4643 hashitem *hi; | 4564 hashitem_T *hi; |
4644 dictitem *item2; | 4565 dictitem_T *item2; |
4645 int todo; | 4566 int todo; |
4646 | 4567 |
4647 if (dict_len(d1) != dict_len(d2)) | 4568 if (dict_len(d1) != dict_len(d2)) |
4648 return FALSE; | 4569 return FALSE; |
4649 | 4570 |
4650 todo = d1->dv_hashtable.ht_used; | 4571 todo = d1->dv_hashtab.ht_used; |
4651 for (hi = d1->dv_hashtable.ht_array; todo > 0; ++hi) | 4572 for (hi = d1->dv_hashtab.ht_array; todo > 0; ++hi) |
4652 { | 4573 { |
4653 if (!HASHITEM_EMPTY(hi)) | 4574 if (!HASHITEM_EMPTY(hi)) |
4654 { | 4575 { |
4655 item2 = dict_find(d2, hi->hi_key, -1); | 4576 item2 = dict_find(d2, hi->hi_key, -1); |
4656 if (item2 == NULL) | 4577 if (item2 == NULL) |
4667 * Return TRUE if "tv1" and "tv2" have the same value. | 4588 * Return TRUE if "tv1" and "tv2" have the same value. |
4668 * Compares the items just like "==" would compare them. | 4589 * Compares the items just like "==" would compare them. |
4669 */ | 4590 */ |
4670 static int | 4591 static int |
4671 tv_equal(tv1, tv2, ic) | 4592 tv_equal(tv1, tv2, ic) |
4672 typeval *tv1; | 4593 typval_T *tv1; |
4673 typeval *tv2; | 4594 typval_T *tv2; |
4674 int ic; /* ignore case */ | 4595 int ic; /* ignore case */ |
4675 { | 4596 { |
4676 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; | 4597 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; |
4677 | 4598 |
4678 if (tv1->v_type == VAR_LIST || tv2->v_type == VAR_LIST) | 4599 if (tv1->v_type == VAR_LIST || tv2->v_type == VAR_LIST) |
4734 /* | 4655 /* |
4735 * Locate item with index "n" in list "l" and return it. | 4656 * Locate item with index "n" in list "l" and return it. |
4736 * A negative index is counted from the end; -1 is the last item. | 4657 * A negative index is counted from the end; -1 is the last item. |
4737 * Returns NULL when "n" is out of range. | 4658 * Returns NULL when "n" is out of range. |
4738 */ | 4659 */ |
4739 static listitem * | 4660 static listitem_T * |
4740 list_find(l, n) | 4661 list_find(l, n) |
4741 listvar *l; | 4662 list_T *l; |
4742 long n; | 4663 long n; |
4743 { | 4664 { |
4744 listitem *item; | 4665 listitem_T *item; |
4745 long idx; | 4666 long idx; |
4746 | 4667 |
4747 if (l == NULL) | 4668 if (l == NULL) |
4748 return NULL; | 4669 return NULL; |
4749 if (n < 0) | 4670 if (n < 0) |
4767 * Locate "item" list "l" and return its index. | 4688 * Locate "item" list "l" and return its index. |
4768 * Returns -1 when "item" is not in the list. | 4689 * Returns -1 when "item" is not in the list. |
4769 */ | 4690 */ |
4770 static long | 4691 static long |
4771 list_idx_of_item(l, item) | 4692 list_idx_of_item(l, item) |
4772 listvar *l; | 4693 list_T *l; |
4773 listitem *item; | 4694 listitem_T *item; |
4774 { | 4695 { |
4775 long idx = 0; | 4696 long idx = 0; |
4776 listitem *li; | 4697 listitem_T *li; |
4777 | 4698 |
4778 if (l == NULL) | 4699 if (l == NULL) |
4779 return -1; | 4700 return -1; |
4780 idx = 0; | 4701 idx = 0; |
4781 for (li = l->lv_first; li != NULL && li != item; li = li->li_next) | 4702 for (li = l->lv_first; li != NULL && li != item; li = li->li_next) |
4789 * Like list_find(), but also find an item just past the end. | 4710 * Like list_find(), but also find an item just past the end. |
4790 * "*ip" is the item to find. | 4711 * "*ip" is the item to find. |
4791 * When found "*ip" is set to zero, when not found "*ip" is non-zero. | 4712 * When found "*ip" is set to zero, when not found "*ip" is non-zero. |
4792 * Returns NULL when item not found or item is just past the end. | 4713 * Returns NULL when item not found or item is just past the end. |
4793 */ | 4714 */ |
4794 static listitem * | 4715 static listitem_T * |
4795 list_find_ext(l, ip) | 4716 list_find_ext(l, ip) |
4796 listvar *l; | 4717 list_T *l; |
4797 long *ip; | 4718 long *ip; |
4798 { | 4719 { |
4799 long n; | 4720 long n; |
4800 listitem *item; | 4721 listitem_T *item; |
4801 | 4722 |
4802 if (*ip < 0) | 4723 if (*ip < 0) |
4803 { | 4724 { |
4804 /* Count from the end: -1 is before last item. */ | 4725 /* Count from the end: -1 is before last item. */ |
4805 item = l->lv_last; | 4726 item = l->lv_last; |
4821 /* | 4742 /* |
4822 * Append item "item" to the end of list "l". | 4743 * Append item "item" to the end of list "l". |
4823 */ | 4744 */ |
4824 static void | 4745 static void |
4825 list_append(l, item) | 4746 list_append(l, item) |
4826 listvar *l; | 4747 list_T *l; |
4827 listitem *item; | 4748 listitem_T *item; |
4828 { | 4749 { |
4829 if (l->lv_last == NULL) | 4750 if (l->lv_last == NULL) |
4830 { | 4751 { |
4831 /* empty list */ | 4752 /* empty list */ |
4832 l->lv_first = item; | 4753 l->lv_first = item; |
4841 } | 4762 } |
4842 item->li_next = NULL; | 4763 item->li_next = NULL; |
4843 } | 4764 } |
4844 | 4765 |
4845 /* | 4766 /* |
4846 * Append typeval "tv" to the end of list "l". | 4767 * Append typval_T "tv" to the end of list "l". |
4847 * Return FAIL when out of memory. | 4768 * Return FAIL when out of memory. |
4848 */ | 4769 */ |
4849 static int | 4770 static int |
4850 list_append_tv(l, tv) | 4771 list_append_tv(l, tv) |
4851 listvar *l; | 4772 list_T *l; |
4852 typeval *tv; | 4773 typval_T *tv; |
4853 { | 4774 { |
4854 listitem *ni = listitem_alloc(); | 4775 listitem_T *ni = listitem_alloc(); |
4855 | 4776 |
4856 if (ni == NULL) | 4777 if (ni == NULL) |
4857 return FAIL; | 4778 return FAIL; |
4858 copy_tv(tv, &ni->li_tv); | 4779 copy_tv(tv, &ni->li_tv); |
4859 list_append(l, ni); | 4780 list_append(l, ni); |
4860 return OK; | 4781 return OK; |
4861 } | 4782 } |
4862 | 4783 |
4863 /* | 4784 /* |
4864 * Insert typeval "tv" in list "l" before "item". | 4785 * Insert typval_T "tv" in list "l" before "item". |
4865 * If "item" is NULL append at the end. | 4786 * If "item" is NULL append at the end. |
4866 * Return FAIL when out of memory. | 4787 * Return FAIL when out of memory. |
4867 */ | 4788 */ |
4868 static int | 4789 static int |
4869 list_insert_tv(l, tv, item) | 4790 list_insert_tv(l, tv, item) |
4870 listvar *l; | 4791 list_T *l; |
4871 typeval *tv; | 4792 typval_T *tv; |
4872 listitem *item; | 4793 listitem_T *item; |
4873 { | 4794 { |
4874 listitem *ni = listitem_alloc(); | 4795 listitem_T *ni = listitem_alloc(); |
4875 | 4796 |
4876 if (ni == NULL) | 4797 if (ni == NULL) |
4877 return FAIL; | 4798 return FAIL; |
4878 copy_tv(tv, &ni->li_tv); | 4799 copy_tv(tv, &ni->li_tv); |
4879 if (item == NULL) | 4800 if (item == NULL) |
4898 * If "bef" is NULL append at the end, otherwise insert before this item. | 4819 * If "bef" is NULL append at the end, otherwise insert before this item. |
4899 * Returns FAIL when out of memory. | 4820 * Returns FAIL when out of memory. |
4900 */ | 4821 */ |
4901 static int | 4822 static int |
4902 list_extend(l1, l2, bef) | 4823 list_extend(l1, l2, bef) |
4903 listvar *l1; | 4824 list_T *l1; |
4904 listvar *l2; | 4825 list_T *l2; |
4905 listitem *bef; | 4826 listitem_T *bef; |
4906 { | 4827 { |
4907 listitem *item; | 4828 listitem_T *item; |
4908 | 4829 |
4909 for (item = l2->lv_first; item != NULL; item = item->li_next) | 4830 for (item = l2->lv_first; item != NULL; item = item->li_next) |
4910 if (list_insert_tv(l1, &item->li_tv, bef) == FAIL) | 4831 if (list_insert_tv(l1, &item->li_tv, bef) == FAIL) |
4911 return FAIL; | 4832 return FAIL; |
4912 return OK; | 4833 return OK; |
4916 * Concatenate lists "l1" and "l2" into a new list, stored in "tv". | 4837 * Concatenate lists "l1" and "l2" into a new list, stored in "tv". |
4917 * Return FAIL when out of memory. | 4838 * Return FAIL when out of memory. |
4918 */ | 4839 */ |
4919 static int | 4840 static int |
4920 list_concat(l1, l2, tv) | 4841 list_concat(l1, l2, tv) |
4921 listvar *l1; | 4842 list_T *l1; |
4922 listvar *l2; | 4843 list_T *l2; |
4923 typeval *tv; | 4844 typval_T *tv; |
4924 { | 4845 { |
4925 listvar *l; | 4846 list_T *l; |
4926 | 4847 |
4927 /* make a copy of the first list. */ | 4848 /* make a copy of the first list. */ |
4928 l = list_copy(l1, FALSE); | 4849 l = list_copy(l1, FALSE); |
4929 if (l == NULL) | 4850 if (l == NULL) |
4930 return FAIL; | 4851 return FAIL; |
4938 /* | 4859 /* |
4939 * Make a copy of list "orig". Shallow if "deep" is FALSE. | 4860 * Make a copy of list "orig". Shallow if "deep" is FALSE. |
4940 * The refcount of the new list is set to 1. | 4861 * The refcount of the new list is set to 1. |
4941 * Returns NULL when out of memory. | 4862 * Returns NULL when out of memory. |
4942 */ | 4863 */ |
4943 static listvar * | 4864 static list_T * |
4944 list_copy(orig, deep) | 4865 list_copy(orig, deep) |
4945 listvar *orig; | 4866 list_T *orig; |
4946 int deep; | 4867 int deep; |
4947 { | 4868 { |
4948 listvar *copy; | 4869 list_T *copy; |
4949 listitem *item; | 4870 listitem_T *item; |
4950 listitem *ni; | 4871 listitem_T *ni; |
4951 | 4872 |
4952 if (orig == NULL) | 4873 if (orig == NULL) |
4953 return NULL; | 4874 return NULL; |
4954 | 4875 |
4955 copy = list_alloc(); | 4876 copy = list_alloc(); |
4976 * Remove items "item" to "item2" from list "l". | 4897 * Remove items "item" to "item2" from list "l". |
4977 * Does not free the listitem or the value! | 4898 * Does not free the listitem or the value! |
4978 */ | 4899 */ |
4979 static void | 4900 static void |
4980 list_remove(l, item, item2) | 4901 list_remove(l, item, item2) |
4981 listvar *l; | 4902 list_T *l; |
4982 listitem *item; | 4903 listitem_T *item; |
4983 listitem *item2; | 4904 listitem_T *item2; |
4984 { | 4905 { |
4985 listitem *ip; | 4906 listitem_T *ip; |
4986 | 4907 |
4987 /* notify watchers */ | 4908 /* notify watchers */ |
4988 for (ip = item; ip != NULL; ip = ip->li_next) | 4909 for (ip = item; ip != NULL; ip = ip->li_next) |
4989 { | 4910 { |
4990 list_fix_watch(l, ip); | 4911 list_fix_watch(l, ip); |
5006 * Return an allocated string with the string representation of a list. | 4927 * Return an allocated string with the string representation of a list. |
5007 * May return NULL. | 4928 * May return NULL. |
5008 */ | 4929 */ |
5009 static char_u * | 4930 static char_u * |
5010 list2string(tv) | 4931 list2string(tv) |
5011 typeval *tv; | 4932 typval_T *tv; |
5012 { | 4933 { |
5013 garray_T ga; | 4934 garray_T ga; |
5014 | 4935 |
5015 if (tv->vval.v_list == NULL) | 4936 if (tv->vval.v_list == NULL) |
5016 return NULL; | 4937 return NULL; |
5027 * When "echo" is TRUE use String as echoed, otherwise as inside a List. | 4948 * When "echo" is TRUE use String as echoed, otherwise as inside a List. |
5028 */ | 4949 */ |
5029 static void | 4950 static void |
5030 list_join(gap, l, sep, echo) | 4951 list_join(gap, l, sep, echo) |
5031 garray_T *gap; | 4952 garray_T *gap; |
5032 listvar *l; | 4953 list_T *l; |
5033 char_u *sep; | 4954 char_u *sep; |
5034 int echo; | 4955 int echo; |
5035 { | 4956 { |
5036 int first = TRUE; | 4957 int first = TRUE; |
5037 char_u *tofree; | 4958 char_u *tofree; |
5038 char_u numbuf[NUMBUFLEN]; | 4959 char_u numbuf[NUMBUFLEN]; |
5039 listitem *item; | 4960 listitem_T *item; |
5040 char_u *s; | 4961 char_u *s; |
5041 | 4962 |
5042 for (item = l->lv_first; item != NULL; item = item->li_next) | 4963 for (item = l->lv_first; item != NULL; item = item->li_next) |
5043 { | 4964 { |
5044 if (first) | 4965 if (first) |
5057 } | 4978 } |
5058 | 4979 |
5059 /* | 4980 /* |
5060 * Allocate an empty header for a dictionary. | 4981 * Allocate an empty header for a dictionary. |
5061 */ | 4982 */ |
5062 static dictvar * | 4983 static dict_T * |
5063 dict_alloc() | 4984 dict_alloc() |
5064 { | 4985 { |
5065 dictvar *d; | 4986 dict_T *d; |
5066 | 4987 |
5067 d = (dictvar *)alloc(sizeof(dictvar)); | 4988 d = (dict_T *)alloc(sizeof(dict_T)); |
5068 if (d != NULL) | 4989 if (d != NULL) |
5069 hash_init(&d->dv_hashtable); | 4990 hash_init(&d->dv_hashtab); |
5070 return d; | 4991 return d; |
5071 } | 4992 } |
5072 | 4993 |
5073 /* | 4994 /* |
5074 * Unreference a Dictionary: decrement the reference count and free it when it | 4995 * Unreference a Dictionary: decrement the reference count and free it when it |
5075 * becomes zero. | 4996 * becomes zero. |
5076 */ | 4997 */ |
5077 static void | 4998 static void |
5078 dict_unref(d) | 4999 dict_unref(d) |
5079 dictvar *d; | 5000 dict_T *d; |
5080 { | 5001 { |
5081 if (d != NULL && --d->dv_refcount <= 0) | 5002 if (d != NULL && --d->dv_refcount <= 0) |
5082 dict_free(d); | 5003 dict_free(d); |
5083 } | 5004 } |
5084 | 5005 |
5086 * Free a Dictionary, including all items it contains. | 5007 * Free a Dictionary, including all items it contains. |
5087 * Ignores the reference count. | 5008 * Ignores the reference count. |
5088 */ | 5009 */ |
5089 static void | 5010 static void |
5090 dict_free(d) | 5011 dict_free(d) |
5091 dictvar *d; | 5012 dict_T *d; |
5092 { | 5013 { |
5093 int todo; | 5014 int todo; |
5094 hashitem *hi; | 5015 hashitem_T *hi; |
5095 | 5016 |
5096 /* Careful: we free the dictitems while they still appear in the | 5017 /* Careful: we free the dictitems while they still appear in the |
5097 * hashtable. Must not try to resize the hashtable! */ | 5018 * hashtab. Must not try to resize the hashtab! */ |
5098 todo = d->dv_hashtable.ht_used; | 5019 todo = d->dv_hashtab.ht_used; |
5099 for (hi = d->dv_hashtable.ht_array; todo > 0; ++hi) | 5020 for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) |
5100 { | 5021 { |
5101 if (!HASHITEM_EMPTY(hi)) | 5022 if (!HASHITEM_EMPTY(hi)) |
5102 { | 5023 { |
5103 dictitem_free(HI2DI(hi)); | 5024 dictitem_free(HI2DI(hi)); |
5104 --todo; | 5025 --todo; |
5105 } | 5026 } |
5106 } | 5027 } |
5107 hash_clear(&d->dv_hashtable); | 5028 hash_clear(&d->dv_hashtab); |
5108 vim_free(d); | 5029 vim_free(d); |
5109 } | 5030 } |
5110 | 5031 |
5111 /* | 5032 /* |
5112 * Allocate a Dictionary item. | 5033 * Allocate a Dictionary item. |
5113 * The "key" is copied to the new item. | 5034 * The "key" is copied to the new item. |
5114 * Note that the value of the item "di_tv" still needs to be initialized! | 5035 * Note that the value of the item "di_tv" still needs to be initialized! |
5115 * Returns NULL when out of memory. | 5036 * Returns NULL when out of memory. |
5116 */ | 5037 */ |
5117 static dictitem * | 5038 static dictitem_T * |
5118 dictitem_alloc(key) | 5039 dictitem_alloc(key) |
5119 char_u *key; | 5040 char_u *key; |
5120 { | 5041 { |
5121 dictitem *di; | 5042 dictitem_T *di; |
5122 | 5043 |
5123 di = (dictitem *)alloc(sizeof(dictitem) + STRLEN(key)); | 5044 di = (dictitem_T *)alloc(sizeof(dictitem_T) + STRLEN(key)); |
5124 if (di != NULL) | 5045 if (di != NULL) |
5125 STRCPY(di->di_key, key); | 5046 STRCPY(di->di_key, key); |
5126 return di; | 5047 return di; |
5127 } | 5048 } |
5128 | 5049 |
5129 /* | 5050 /* |
5130 * Make a copy of a Dictionary item. | 5051 * Make a copy of a Dictionary item. |
5131 */ | 5052 */ |
5132 static dictitem * | 5053 static dictitem_T * |
5133 dictitem_copy(org) | 5054 dictitem_copy(org) |
5134 dictitem *org; | 5055 dictitem_T *org; |
5135 { | 5056 { |
5136 dictitem *di; | 5057 dictitem_T *di; |
5137 | 5058 |
5138 di = (dictitem *)alloc(sizeof(dictitem) + STRLEN(org->di_key)); | 5059 di = (dictitem_T *)alloc(sizeof(dictitem_T) + STRLEN(org->di_key)); |
5139 if (di != NULL) | 5060 if (di != NULL) |
5140 { | 5061 { |
5141 STRCPY(di->di_key, org->di_key); | 5062 STRCPY(di->di_key, org->di_key); |
5142 copy_tv(&org->di_tv, &di->di_tv); | 5063 copy_tv(&org->di_tv, &di->di_tv); |
5143 } | 5064 } |
5147 /* | 5068 /* |
5148 * Remove item "item" from Dictionary "dict" and free it. | 5069 * Remove item "item" from Dictionary "dict" and free it. |
5149 */ | 5070 */ |
5150 static void | 5071 static void |
5151 dictitem_remove(dict, item) | 5072 dictitem_remove(dict, item) |
5152 dictvar *dict; | 5073 dict_T *dict; |
5153 dictitem *item; | 5074 dictitem_T *item; |
5154 { | 5075 { |
5155 hashitem *hi; | 5076 hashitem_T *hi; |
5156 | 5077 |
5157 hi = hash_find(&dict->dv_hashtable, item->di_key); | 5078 hi = hash_find(&dict->dv_hashtab, item->di_key); |
5158 if (HASHITEM_EMPTY(hi)) | 5079 if (HASHITEM_EMPTY(hi)) |
5159 EMSG2(_(e_intern2), "dictitem_remove()"); | 5080 EMSG2(_(e_intern2), "dictitem_remove()"); |
5160 else | 5081 else |
5161 hash_remove(&dict->dv_hashtable, hi); | 5082 hash_remove(&dict->dv_hashtab, hi); |
5162 dictitem_free(item); | 5083 dictitem_free(item); |
5163 } | 5084 } |
5164 | 5085 |
5165 /* | 5086 /* |
5166 * Free a dict item. Also clears the value. | 5087 * Free a dict item. Also clears the value. |
5167 */ | 5088 */ |
5168 static void | 5089 static void |
5169 dictitem_free(item) | 5090 dictitem_free(item) |
5170 dictitem *item; | 5091 dictitem_T *item; |
5171 { | 5092 { |
5172 clear_tv(&item->di_tv); | 5093 clear_tv(&item->di_tv); |
5173 vim_free(item); | 5094 vim_free(item); |
5174 } | 5095 } |
5175 | 5096 |
5176 /* | 5097 /* |
5177 * Make a copy of dict "d". Shallow if "deep" is FALSE. | 5098 * Make a copy of dict "d". Shallow if "deep" is FALSE. |
5178 * The refcount of the new dict is set to 1. | 5099 * The refcount of the new dict is set to 1. |
5179 * Returns NULL when out of memory. | 5100 * Returns NULL when out of memory. |
5180 */ | 5101 */ |
5181 static dictvar * | 5102 static dict_T * |
5182 dict_copy(orig, deep) | 5103 dict_copy(orig, deep) |
5183 dictvar *orig; | 5104 dict_T *orig; |
5184 int deep; | 5105 int deep; |
5185 { | 5106 { |
5186 dictvar *copy; | 5107 dict_T *copy; |
5187 dictitem *di; | 5108 dictitem_T *di; |
5188 int todo; | 5109 int todo; |
5189 hashitem *hi; | 5110 hashitem_T *hi; |
5190 | 5111 |
5191 if (orig == NULL) | 5112 if (orig == NULL) |
5192 return NULL; | 5113 return NULL; |
5193 | 5114 |
5194 copy = dict_alloc(); | 5115 copy = dict_alloc(); |
5195 if (copy != NULL) | 5116 if (copy != NULL) |
5196 { | 5117 { |
5197 todo = orig->dv_hashtable.ht_used; | 5118 todo = orig->dv_hashtab.ht_used; |
5198 for (hi = orig->dv_hashtable.ht_array; todo > 0; ++hi) | 5119 for (hi = orig->dv_hashtab.ht_array; todo > 0; ++hi) |
5199 { | 5120 { |
5200 if (!HASHITEM_EMPTY(hi)) | 5121 if (!HASHITEM_EMPTY(hi)) |
5201 { | 5122 { |
5202 --todo; | 5123 --todo; |
5203 | 5124 |
5226 * Add item "item" to Dictionary "d". | 5147 * Add item "item" to Dictionary "d". |
5227 * Returns FAIL when out of memory and when key already existed. | 5148 * Returns FAIL when out of memory and when key already existed. |
5228 */ | 5149 */ |
5229 static int | 5150 static int |
5230 dict_add(d, item) | 5151 dict_add(d, item) |
5231 dictvar *d; | 5152 dict_T *d; |
5232 dictitem *item; | 5153 dictitem_T *item; |
5233 { | 5154 { |
5234 return hash_add(&d->dv_hashtable, item->di_key); | 5155 return hash_add(&d->dv_hashtab, item->di_key); |
5235 } | 5156 } |
5236 | 5157 |
5237 /* | 5158 /* |
5238 * Get the number of items in a Dictionary. | 5159 * Get the number of items in a Dictionary. |
5239 */ | 5160 */ |
5240 static long | 5161 static long |
5241 dict_len(d) | 5162 dict_len(d) |
5242 dictvar *d; | 5163 dict_T *d; |
5243 { | 5164 { |
5244 if (d == NULL) | 5165 if (d == NULL) |
5245 return 0L; | 5166 return 0L; |
5246 return d->dv_hashtable.ht_used; | 5167 return d->dv_hashtab.ht_used; |
5247 } | 5168 } |
5248 | 5169 |
5249 /* | 5170 /* |
5250 * Find item "key[len]" in Dictionary "d". | 5171 * Find item "key[len]" in Dictionary "d". |
5251 * If "len" is negative use strlen(key). | 5172 * If "len" is negative use strlen(key). |
5252 * Returns NULL when not found. | 5173 * Returns NULL when not found. |
5253 */ | 5174 */ |
5254 static dictitem * | 5175 static dictitem_T * |
5255 dict_find(d, key, len) | 5176 dict_find(d, key, len) |
5256 dictvar *d; | 5177 dict_T *d; |
5257 char_u *key; | 5178 char_u *key; |
5258 int len; | 5179 int len; |
5259 { | 5180 { |
5260 #define AKEYLEN 200 | 5181 #define AKEYLEN 200 |
5261 char_u buf[AKEYLEN]; | 5182 char_u buf[AKEYLEN]; |
5262 char_u *akey; | 5183 char_u *akey; |
5263 char_u *tofree = NULL; | 5184 char_u *tofree = NULL; |
5264 hashitem *hi; | 5185 hashitem_T *hi; |
5265 | 5186 |
5266 if (len < 0) | 5187 if (len < 0) |
5267 akey = key; | 5188 akey = key; |
5268 else if (len >= AKEYLEN) | 5189 else if (len >= AKEYLEN) |
5269 { | 5190 { |
5277 STRNCPY(buf, key, len); | 5198 STRNCPY(buf, key, len); |
5278 buf[len] = NUL; | 5199 buf[len] = NUL; |
5279 akey = buf; | 5200 akey = buf; |
5280 } | 5201 } |
5281 | 5202 |
5282 hi = hash_find(&d->dv_hashtable, akey); | 5203 hi = hash_find(&d->dv_hashtab, akey); |
5283 vim_free(tofree); | 5204 vim_free(tofree); |
5284 if (HASHITEM_EMPTY(hi)) | 5205 if (HASHITEM_EMPTY(hi)) |
5285 return NULL; | 5206 return NULL; |
5286 return HI2DI(hi); | 5207 return HI2DI(hi); |
5287 } | 5208 } |
5290 * Return an allocated string with the string representation of a Dictionary. | 5211 * Return an allocated string with the string representation of a Dictionary. |
5291 * May return NULL. | 5212 * May return NULL. |
5292 */ | 5213 */ |
5293 static char_u * | 5214 static char_u * |
5294 dict2string(tv) | 5215 dict2string(tv) |
5295 typeval *tv; | 5216 typval_T *tv; |
5296 { | 5217 { |
5297 garray_T ga; | 5218 garray_T ga; |
5298 int first = TRUE; | 5219 int first = TRUE; |
5299 char_u *tofree; | 5220 char_u *tofree; |
5300 char_u numbuf[NUMBUFLEN]; | 5221 char_u numbuf[NUMBUFLEN]; |
5301 hashitem *hi; | 5222 hashitem_T *hi; |
5302 char_u *s; | 5223 char_u *s; |
5303 dictvar *d; | 5224 dict_T *d; |
5304 int todo; | 5225 int todo; |
5305 | 5226 |
5306 if ((d = tv->vval.v_dict) == NULL) | 5227 if ((d = tv->vval.v_dict) == NULL) |
5307 return NULL; | 5228 return NULL; |
5308 ga_init2(&ga, (int)sizeof(char), 80); | 5229 ga_init2(&ga, (int)sizeof(char), 80); |
5309 ga_append(&ga, '{'); | 5230 ga_append(&ga, '{'); |
5310 | 5231 |
5311 todo = d->dv_hashtable.ht_used; | 5232 todo = d->dv_hashtab.ht_used; |
5312 for (hi = d->dv_hashtable.ht_array; todo > 0; ++hi) | 5233 for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) |
5313 { | 5234 { |
5314 if (!HASHITEM_EMPTY(hi)) | 5235 if (!HASHITEM_EMPTY(hi)) |
5315 { | 5236 { |
5316 --todo; | 5237 --todo; |
5317 | 5238 |
5344 * Return OK or FAIL. Returns NOTDONE for {expr}. | 5265 * Return OK or FAIL. Returns NOTDONE for {expr}. |
5345 */ | 5266 */ |
5346 static int | 5267 static int |
5347 get_dict_tv(arg, rettv, evaluate) | 5268 get_dict_tv(arg, rettv, evaluate) |
5348 char_u **arg; | 5269 char_u **arg; |
5349 typeval *rettv; | 5270 typval_T *rettv; |
5350 int evaluate; | 5271 int evaluate; |
5351 { | 5272 { |
5352 dictvar *d = NULL; | 5273 dict_T *d = NULL; |
5353 typeval tvkey; | 5274 typval_T tvkey; |
5354 typeval tv; | 5275 typval_T tv; |
5355 char_u *key; | 5276 char_u *key; |
5356 dictitem *item; | 5277 dictitem_T *item; |
5357 char_u *start = skipwhite(*arg + 1); | 5278 char_u *start = skipwhite(*arg + 1); |
5358 char_u buf[NUMBUFLEN]; | 5279 char_u buf[NUMBUFLEN]; |
5359 | 5280 |
5360 /* | 5281 /* |
5361 * First check if it's not a curly-braces thing: {expr}. | 5282 * First check if it's not a curly-braces thing: {expr}. |
5463 * Does not put quotes around strings, as ":echo" displays values. | 5384 * Does not put quotes around strings, as ":echo" displays values. |
5464 * May return NULL; | 5385 * May return NULL; |
5465 */ | 5386 */ |
5466 static char_u * | 5387 static char_u * |
5467 echo_string(tv, tofree, numbuf) | 5388 echo_string(tv, tofree, numbuf) |
5468 typeval *tv; | 5389 typval_T *tv; |
5469 char_u **tofree; | 5390 char_u **tofree; |
5470 char_u *numbuf; | 5391 char_u *numbuf; |
5471 { | 5392 { |
5472 static int recurse = 0; | 5393 static int recurse = 0; |
5473 char_u *r = NULL; | 5394 char_u *r = NULL; |
5474 | 5395 |
5475 if (recurse >= VAR_MAXNEST) | 5396 if (recurse >= DICT_MAXNEST) |
5476 { | 5397 { |
5477 EMSG(_("E724: variable nested too deep for displaying")); | 5398 EMSG(_("E724: variable nested too deep for displaying")); |
5478 *tofree = NULL; | 5399 *tofree = NULL; |
5479 return NULL; | 5400 return NULL; |
5480 } | 5401 } |
5515 * Puts quotes around strings, so that they can be parsed back by eval(). | 5436 * Puts quotes around strings, so that they can be parsed back by eval(). |
5516 * May return NULL; | 5437 * May return NULL; |
5517 */ | 5438 */ |
5518 static char_u * | 5439 static char_u * |
5519 tv2string(tv, tofree, numbuf) | 5440 tv2string(tv, tofree, numbuf) |
5520 typeval *tv; | 5441 typval_T *tv; |
5521 char_u **tofree; | 5442 char_u **tofree; |
5522 char_u *numbuf; | 5443 char_u *numbuf; |
5523 { | 5444 { |
5524 switch (tv->v_type) | 5445 switch (tv->v_type) |
5525 { | 5446 { |
5538 } | 5459 } |
5539 return echo_string(tv, tofree, numbuf); | 5460 return echo_string(tv, tofree, numbuf); |
5540 } | 5461 } |
5541 | 5462 |
5542 /* | 5463 /* |
5543 * Return a string in ' quotes, doubling ' characters. | 5464 * Return string "str" in ' quotes, doubling ' characters. |
5465 * If "str" is NULL an empty string is assumed. | |
5544 * If "function" is TRUE make it function('string'). | 5466 * If "function" is TRUE make it function('string'). |
5545 */ | 5467 */ |
5546 static char_u * | 5468 static char_u * |
5547 string_quote(str, function) | 5469 string_quote(str, function) |
5548 char_u *str; | 5470 char_u *str; |
5549 int function; | 5471 int function; |
5550 { | 5472 { |
5551 unsigned len = STRLEN(str) + (function ? 13 : 3); | 5473 unsigned len; |
5552 char_u *p, *r, *s; | 5474 char_u *p, *r, *s; |
5553 | 5475 |
5554 for (p = str; *p != NUL; mb_ptr_adv(p)) | 5476 len = (function ? 13 : 3); |
5555 if (*p == '\'') | 5477 if (str != NULL) |
5556 ++len; | 5478 { |
5479 len += STRLEN(str); | |
5480 for (p = str; *p != NUL; mb_ptr_adv(p)) | |
5481 if (*p == '\'') | |
5482 ++len; | |
5483 } | |
5557 s = r = alloc(len); | 5484 s = r = alloc(len); |
5558 if (r != NULL) | 5485 if (r != NULL) |
5559 { | 5486 { |
5560 if (function) | 5487 if (function) |
5561 { | 5488 { |
5562 STRCPY(r, "function('"); | 5489 STRCPY(r, "function('"); |
5563 r += 10; | 5490 r += 10; |
5564 } | 5491 } |
5565 else | 5492 else |
5566 *r++ = '\''; | 5493 *r++ = '\''; |
5567 for (p = str; *p != NUL; ) | 5494 if (str != NULL) |
5568 { | 5495 for (p = str; *p != NUL; ) |
5569 if (*p == '\'') | 5496 { |
5570 *r++ = '\''; | 5497 if (*p == '\'') |
5571 MB_COPY_CHAR(p, r); | 5498 *r++ = '\''; |
5572 } | 5499 MB_COPY_CHAR(p, r); |
5500 } | |
5573 *r++ = '\''; | 5501 *r++ = '\''; |
5574 if (function) | 5502 if (function) |
5575 *r++ = ')'; | 5503 *r++ = ')'; |
5576 *r++ = NUL; | 5504 *r++ = NUL; |
5577 } | 5505 } |
5585 * Always return OK. | 5513 * Always return OK. |
5586 */ | 5514 */ |
5587 static int | 5515 static int |
5588 get_env_tv(arg, rettv, evaluate) | 5516 get_env_tv(arg, rettv, evaluate) |
5589 char_u **arg; | 5517 char_u **arg; |
5590 typeval *rettv; | 5518 typval_T *rettv; |
5591 int evaluate; | 5519 int evaluate; |
5592 { | 5520 { |
5593 char_u *string = NULL; | 5521 char_u *string = NULL; |
5594 int len; | 5522 int len; |
5595 int cc; | 5523 int cc; |
5634 static struct fst | 5562 static struct fst |
5635 { | 5563 { |
5636 char *f_name; /* function name */ | 5564 char *f_name; /* function name */ |
5637 char f_min_argc; /* minimal number of arguments */ | 5565 char f_min_argc; /* minimal number of arguments */ |
5638 char f_max_argc; /* maximal number of arguments */ | 5566 char f_max_argc; /* maximal number of arguments */ |
5639 void (*f_func) __ARGS((typeval *args, typeval *rvar)); | 5567 void (*f_func) __ARGS((typval_T *args, typval_T *rvar)); |
5640 /* implemenation of function */ | 5568 /* implemenation of function */ |
5641 } functions[] = | 5569 } functions[] = |
5642 { | 5570 { |
5643 {"add", 2, 2, f_add}, | 5571 {"add", 2, 2, f_add}, |
5644 {"append", 2, 2, f_append}, | 5572 {"append", 2, 2, f_append}, |
5783 {"sort", 1, 2, f_sort}, | 5711 {"sort", 1, 2, f_sort}, |
5784 {"split", 1, 2, f_split}, | 5712 {"split", 1, 2, f_split}, |
5785 #ifdef HAVE_STRFTIME | 5713 #ifdef HAVE_STRFTIME |
5786 {"strftime", 1, 2, f_strftime}, | 5714 {"strftime", 1, 2, f_strftime}, |
5787 #endif | 5715 #endif |
5788 {"stridx", 2, 2, f_stridx}, | 5716 {"stridx", 2, 3, f_stridx}, |
5789 {"string", 1, 1, f_string}, | 5717 {"string", 1, 1, f_string}, |
5790 {"strlen", 1, 1, f_strlen}, | 5718 {"strlen", 1, 1, f_strlen}, |
5791 {"strpart", 2, 3, f_strpart}, | 5719 {"strpart", 2, 3, f_strpart}, |
5792 {"strridx", 2, 2, f_strridx}, | 5720 {"strridx", 2, 2, f_strridx}, |
5793 {"strtrans", 1, 1, f_strtrans}, | 5721 {"strtrans", 1, 1, f_strtrans}, |
5911 static char_u * | 5839 static char_u * |
5912 deref_func_name(name, lenp) | 5840 deref_func_name(name, lenp) |
5913 char_u *name; | 5841 char_u *name; |
5914 int *lenp; | 5842 int *lenp; |
5915 { | 5843 { |
5916 VAR v; | 5844 dictitem_T *v; |
5917 int cc; | 5845 int cc; |
5918 | 5846 |
5919 cc = name[*lenp]; | 5847 cc = name[*lenp]; |
5920 name[*lenp] = NUL; | 5848 name[*lenp] = NUL; |
5921 v = find_var(name, NULL); | 5849 v = find_var(name, NULL); |
5922 name[*lenp] = cc; | 5850 name[*lenp] = cc; |
5923 if (v != NULL && v->tv.v_type == VAR_FUNC) | 5851 if (v != NULL && v->di_tv.v_type == VAR_FUNC) |
5924 { | 5852 { |
5925 if (v->tv.vval.v_string == NULL) | 5853 if (v->di_tv.vval.v_string == NULL) |
5926 { | 5854 { |
5927 *lenp = 0; | 5855 *lenp = 0; |
5928 return (char_u *)""; /* just in case */ | 5856 return (char_u *)""; /* just in case */ |
5929 } | 5857 } |
5930 *lenp = STRLEN(v->tv.vval.v_string); | 5858 *lenp = STRLEN(v->di_tv.vval.v_string); |
5931 return v->tv.vval.v_string; | 5859 return v->di_tv.vval.v_string; |
5932 } | 5860 } |
5933 | 5861 |
5934 return name; | 5862 return name; |
5935 } | 5863 } |
5936 | 5864 |
5941 static int | 5869 static int |
5942 get_func_tv(name, len, rettv, arg, firstline, lastline, doesrange, | 5870 get_func_tv(name, len, rettv, arg, firstline, lastline, doesrange, |
5943 evaluate, selfdict) | 5871 evaluate, selfdict) |
5944 char_u *name; /* name of the function */ | 5872 char_u *name; /* name of the function */ |
5945 int len; /* length of "name" */ | 5873 int len; /* length of "name" */ |
5946 typeval *rettv; | 5874 typval_T *rettv; |
5947 char_u **arg; /* argument, pointing to the '(' */ | 5875 char_u **arg; /* argument, pointing to the '(' */ |
5948 linenr_T firstline; /* first line of range */ | 5876 linenr_T firstline; /* first line of range */ |
5949 linenr_T lastline; /* last line of range */ | 5877 linenr_T lastline; /* last line of range */ |
5950 int *doesrange; /* return: function handled range */ | 5878 int *doesrange; /* return: function handled range */ |
5951 int evaluate; | 5879 int evaluate; |
5952 dictvar *selfdict; /* Dictionary for "self" */ | 5880 dict_T *selfdict; /* Dictionary for "self" */ |
5953 { | 5881 { |
5954 char_u *argp; | 5882 char_u *argp; |
5955 int ret = OK; | 5883 int ret = OK; |
5956 #define MAX_FUNC_ARGS 20 | 5884 typval_T argvars[MAX_FUNC_ARGS]; /* vars for arguments */ |
5957 typeval argvars[MAX_FUNC_ARGS]; /* vars for arguments */ | |
5958 int argcount = 0; /* number of arguments found */ | 5885 int argcount = 0; /* number of arguments found */ |
5959 | 5886 |
5960 /* | 5887 /* |
5961 * Get the arguments. | 5888 * Get the arguments. |
5962 */ | 5889 */ |
5982 | 5909 |
5983 if (ret == OK) | 5910 if (ret == OK) |
5984 ret = call_func(name, len, rettv, argcount, argvars, | 5911 ret = call_func(name, len, rettv, argcount, argvars, |
5985 firstline, lastline, doesrange, evaluate, selfdict); | 5912 firstline, lastline, doesrange, evaluate, selfdict); |
5986 else if (!aborting()) | 5913 else if (!aborting()) |
5987 EMSG2(_("E116: Invalid arguments for function %s"), name); | 5914 { |
5915 if (argcount == MAX_FUNC_ARGS) | |
5916 EMSG2(_("E740: Too many arguments for function %s"), name); | |
5917 else | |
5918 EMSG2(_("E116: Invalid arguments for function %s"), name); | |
5919 } | |
5988 | 5920 |
5989 while (--argcount >= 0) | 5921 while (--argcount >= 0) |
5990 clear_tv(&argvars[argcount]); | 5922 clear_tv(&argvars[argcount]); |
5991 | 5923 |
5992 *arg = skipwhite(argp); | 5924 *arg = skipwhite(argp); |
6001 static int | 5933 static int |
6002 call_func(name, len, rettv, argcount, argvars, firstline, lastline, | 5934 call_func(name, len, rettv, argcount, argvars, firstline, lastline, |
6003 doesrange, evaluate, selfdict) | 5935 doesrange, evaluate, selfdict) |
6004 char_u *name; /* name of the function */ | 5936 char_u *name; /* name of the function */ |
6005 int len; /* length of "name" */ | 5937 int len; /* length of "name" */ |
6006 typeval *rettv; /* return value goes here */ | 5938 typval_T *rettv; /* return value goes here */ |
6007 int argcount; /* number of "argvars" */ | 5939 int argcount; /* number of "argvars" */ |
6008 typeval *argvars; /* vars for arguments */ | 5940 typval_T *argvars; /* vars for arguments */ |
6009 linenr_T firstline; /* first line of range */ | 5941 linenr_T firstline; /* first line of range */ |
6010 linenr_T lastline; /* last line of range */ | 5942 linenr_T lastline; /* last line of range */ |
6011 int *doesrange; /* return: function handled range */ | 5943 int *doesrange; /* return: function handled range */ |
6012 int evaluate; | 5944 int evaluate; |
6013 dictvar *selfdict; /* Dictionary for "self" */ | 5945 dict_T *selfdict; /* Dictionary for "self" */ |
6014 { | 5946 { |
6015 int ret = FAIL; | 5947 int ret = FAIL; |
6016 #define ERROR_UNKNOWN 0 | 5948 #define ERROR_UNKNOWN 0 |
6017 #define ERROR_TOOMANY 1 | 5949 #define ERROR_TOOMANY 1 |
6018 #define ERROR_TOOFEW 2 | 5950 #define ERROR_TOOFEW 2 |
6212 /* | 6144 /* |
6213 * "add(list, item)" function | 6145 * "add(list, item)" function |
6214 */ | 6146 */ |
6215 static void | 6147 static void |
6216 f_add(argvars, rettv) | 6148 f_add(argvars, rettv) |
6217 typeval *argvars; | 6149 typval_T *argvars; |
6218 typeval *rettv; | 6150 typval_T *rettv; |
6219 { | 6151 { |
6220 listvar *l; | 6152 list_T *l; |
6221 | 6153 |
6222 rettv->vval.v_number = 1; /* Default: Failed */ | 6154 rettv->vval.v_number = 1; /* Default: Failed */ |
6223 if (argvars[0].v_type == VAR_LIST) | 6155 if (argvars[0].v_type == VAR_LIST) |
6224 { | 6156 { |
6225 l = argvars[0].vval.v_list; | 6157 l = argvars[0].vval.v_list; |
6233 /* | 6165 /* |
6234 * "append(lnum, string/list)" function | 6166 * "append(lnum, string/list)" function |
6235 */ | 6167 */ |
6236 static void | 6168 static void |
6237 f_append(argvars, rettv) | 6169 f_append(argvars, rettv) |
6238 typeval *argvars; | 6170 typval_T *argvars; |
6239 typeval *rettv; | 6171 typval_T *rettv; |
6240 { | 6172 { |
6241 long lnum; | 6173 long lnum; |
6242 listvar *l = NULL; | 6174 list_T *l = NULL; |
6243 listitem *li = NULL; | 6175 listitem_T *li = NULL; |
6244 typeval *tv; | 6176 typval_T *tv; |
6245 long added = 0; | 6177 long added = 0; |
6246 | 6178 |
6247 rettv->vval.v_number = 1; /* Default: Failed */ | 6179 rettv->vval.v_number = 1; /* Default: Failed */ |
6248 lnum = get_tv_lnum(argvars); | 6180 lnum = get_tv_lnum(argvars); |
6249 if (lnum >= 0 | 6181 if (lnum >= 0 |
6283 * "argc()" function | 6215 * "argc()" function |
6284 */ | 6216 */ |
6285 /* ARGSUSED */ | 6217 /* ARGSUSED */ |
6286 static void | 6218 static void |
6287 f_argc(argvars, rettv) | 6219 f_argc(argvars, rettv) |
6288 typeval *argvars; | 6220 typval_T *argvars; |
6289 typeval *rettv; | 6221 typval_T *rettv; |
6290 { | 6222 { |
6291 rettv->vval.v_number = ARGCOUNT; | 6223 rettv->vval.v_number = ARGCOUNT; |
6292 } | 6224 } |
6293 | 6225 |
6294 /* | 6226 /* |
6295 * "argidx()" function | 6227 * "argidx()" function |
6296 */ | 6228 */ |
6297 /* ARGSUSED */ | 6229 /* ARGSUSED */ |
6298 static void | 6230 static void |
6299 f_argidx(argvars, rettv) | 6231 f_argidx(argvars, rettv) |
6300 typeval *argvars; | 6232 typval_T *argvars; |
6301 typeval *rettv; | 6233 typval_T *rettv; |
6302 { | 6234 { |
6303 rettv->vval.v_number = curwin->w_arg_idx; | 6235 rettv->vval.v_number = curwin->w_arg_idx; |
6304 } | 6236 } |
6305 | 6237 |
6306 /* | 6238 /* |
6307 * "argv(nr)" function | 6239 * "argv(nr)" function |
6308 */ | 6240 */ |
6309 static void | 6241 static void |
6310 f_argv(argvars, rettv) | 6242 f_argv(argvars, rettv) |
6311 typeval *argvars; | 6243 typval_T *argvars; |
6312 typeval *rettv; | 6244 typval_T *rettv; |
6313 { | 6245 { |
6314 int idx; | 6246 int idx; |
6315 | 6247 |
6316 idx = get_tv_number(&argvars[0]); | 6248 idx = get_tv_number(&argvars[0]); |
6317 if (idx >= 0 && idx < ARGCOUNT) | 6249 if (idx >= 0 && idx < ARGCOUNT) |
6325 * "browse(save, title, initdir, default)" function | 6257 * "browse(save, title, initdir, default)" function |
6326 */ | 6258 */ |
6327 /* ARGSUSED */ | 6259 /* ARGSUSED */ |
6328 static void | 6260 static void |
6329 f_browse(argvars, rettv) | 6261 f_browse(argvars, rettv) |
6330 typeval *argvars; | 6262 typval_T *argvars; |
6331 typeval *rettv; | 6263 typval_T *rettv; |
6332 { | 6264 { |
6333 #ifdef FEAT_BROWSE | 6265 #ifdef FEAT_BROWSE |
6334 int save; | 6266 int save; |
6335 char_u *title; | 6267 char_u *title; |
6336 char_u *initdir; | 6268 char_u *initdir; |
6356 * "browsedir(title, initdir)" function | 6288 * "browsedir(title, initdir)" function |
6357 */ | 6289 */ |
6358 /* ARGSUSED */ | 6290 /* ARGSUSED */ |
6359 static void | 6291 static void |
6360 f_browsedir(argvars, rettv) | 6292 f_browsedir(argvars, rettv) |
6361 typeval *argvars; | 6293 typval_T *argvars; |
6362 typeval *rettv; | 6294 typval_T *rettv; |
6363 { | 6295 { |
6364 #ifdef FEAT_BROWSE | 6296 #ifdef FEAT_BROWSE |
6365 char_u *title; | 6297 char_u *title; |
6366 char_u *initdir; | 6298 char_u *initdir; |
6367 char_u buf[NUMBUFLEN]; | 6299 char_u buf[NUMBUFLEN]; |
6375 rettv->vval.v_string = NULL; | 6307 rettv->vval.v_string = NULL; |
6376 #endif | 6308 #endif |
6377 rettv->v_type = VAR_STRING; | 6309 rettv->v_type = VAR_STRING; |
6378 } | 6310 } |
6379 | 6311 |
6380 static buf_T *find_buffer __ARGS((typeval *avar)); | 6312 static buf_T *find_buffer __ARGS((typval_T *avar)); |
6381 | 6313 |
6382 /* | 6314 /* |
6383 * Find a buffer by number or exact name. | 6315 * Find a buffer by number or exact name. |
6384 */ | 6316 */ |
6385 static buf_T * | 6317 static buf_T * |
6386 find_buffer(avar) | 6318 find_buffer(avar) |
6387 typeval *avar; | 6319 typval_T *avar; |
6388 { | 6320 { |
6389 buf_T *buf = NULL; | 6321 buf_T *buf = NULL; |
6390 | 6322 |
6391 if (avar->v_type == VAR_NUMBER) | 6323 if (avar->v_type == VAR_NUMBER) |
6392 buf = buflist_findnr((int)avar->vval.v_number); | 6324 buf = buflist_findnr((int)avar->vval.v_number); |
6414 /* | 6346 /* |
6415 * "bufexists(expr)" function | 6347 * "bufexists(expr)" function |
6416 */ | 6348 */ |
6417 static void | 6349 static void |
6418 f_bufexists(argvars, rettv) | 6350 f_bufexists(argvars, rettv) |
6419 typeval *argvars; | 6351 typval_T *argvars; |
6420 typeval *rettv; | 6352 typval_T *rettv; |
6421 { | 6353 { |
6422 rettv->vval.v_number = (find_buffer(&argvars[0]) != NULL); | 6354 rettv->vval.v_number = (find_buffer(&argvars[0]) != NULL); |
6423 } | 6355 } |
6424 | 6356 |
6425 /* | 6357 /* |
6426 * "buflisted(expr)" function | 6358 * "buflisted(expr)" function |
6427 */ | 6359 */ |
6428 static void | 6360 static void |
6429 f_buflisted(argvars, rettv) | 6361 f_buflisted(argvars, rettv) |
6430 typeval *argvars; | 6362 typval_T *argvars; |
6431 typeval *rettv; | 6363 typval_T *rettv; |
6432 { | 6364 { |
6433 buf_T *buf; | 6365 buf_T *buf; |
6434 | 6366 |
6435 buf = find_buffer(&argvars[0]); | 6367 buf = find_buffer(&argvars[0]); |
6436 rettv->vval.v_number = (buf != NULL && buf->b_p_bl); | 6368 rettv->vval.v_number = (buf != NULL && buf->b_p_bl); |
6439 /* | 6371 /* |
6440 * "bufloaded(expr)" function | 6372 * "bufloaded(expr)" function |
6441 */ | 6373 */ |
6442 static void | 6374 static void |
6443 f_bufloaded(argvars, rettv) | 6375 f_bufloaded(argvars, rettv) |
6444 typeval *argvars; | 6376 typval_T *argvars; |
6445 typeval *rettv; | 6377 typval_T *rettv; |
6446 { | 6378 { |
6447 buf_T *buf; | 6379 buf_T *buf; |
6448 | 6380 |
6449 buf = find_buffer(&argvars[0]); | 6381 buf = find_buffer(&argvars[0]); |
6450 rettv->vval.v_number = (buf != NULL && buf->b_ml.ml_mfp != NULL); | 6382 rettv->vval.v_number = (buf != NULL && buf->b_ml.ml_mfp != NULL); |
6451 } | 6383 } |
6452 | 6384 |
6453 static buf_T *get_buf_tv __ARGS((typeval *tv)); | 6385 static buf_T *get_buf_tv __ARGS((typval_T *tv)); |
6454 | 6386 |
6455 /* | 6387 /* |
6456 * Get buffer by number or pattern. | 6388 * Get buffer by number or pattern. |
6457 */ | 6389 */ |
6458 static buf_T * | 6390 static buf_T * |
6459 get_buf_tv(tv) | 6391 get_buf_tv(tv) |
6460 typeval *tv; | 6392 typval_T *tv; |
6461 { | 6393 { |
6462 char_u *name = tv->vval.v_string; | 6394 char_u *name = tv->vval.v_string; |
6463 int save_magic; | 6395 int save_magic; |
6464 char_u *save_cpo; | 6396 char_u *save_cpo; |
6465 buf_T *buf; | 6397 buf_T *buf; |
6493 /* | 6425 /* |
6494 * "bufname(expr)" function | 6426 * "bufname(expr)" function |
6495 */ | 6427 */ |
6496 static void | 6428 static void |
6497 f_bufname(argvars, rettv) | 6429 f_bufname(argvars, rettv) |
6498 typeval *argvars; | 6430 typval_T *argvars; |
6499 typeval *rettv; | 6431 typval_T *rettv; |
6500 { | 6432 { |
6501 buf_T *buf; | 6433 buf_T *buf; |
6502 | 6434 |
6503 ++emsg_off; | 6435 ++emsg_off; |
6504 buf = get_buf_tv(&argvars[0]); | 6436 buf = get_buf_tv(&argvars[0]); |
6513 /* | 6445 /* |
6514 * "bufnr(expr)" function | 6446 * "bufnr(expr)" function |
6515 */ | 6447 */ |
6516 static void | 6448 static void |
6517 f_bufnr(argvars, rettv) | 6449 f_bufnr(argvars, rettv) |
6518 typeval *argvars; | 6450 typval_T *argvars; |
6519 typeval *rettv; | 6451 typval_T *rettv; |
6520 { | 6452 { |
6521 buf_T *buf; | 6453 buf_T *buf; |
6522 | 6454 |
6523 ++emsg_off; | 6455 ++emsg_off; |
6524 buf = get_buf_tv(&argvars[0]); | 6456 buf = get_buf_tv(&argvars[0]); |
6532 /* | 6464 /* |
6533 * "bufwinnr(nr)" function | 6465 * "bufwinnr(nr)" function |
6534 */ | 6466 */ |
6535 static void | 6467 static void |
6536 f_bufwinnr(argvars, rettv) | 6468 f_bufwinnr(argvars, rettv) |
6537 typeval *argvars; | 6469 typval_T *argvars; |
6538 typeval *rettv; | 6470 typval_T *rettv; |
6539 { | 6471 { |
6540 #ifdef FEAT_WINDOWS | 6472 #ifdef FEAT_WINDOWS |
6541 win_T *wp; | 6473 win_T *wp; |
6542 int winnr = 0; | 6474 int winnr = 0; |
6543 #endif | 6475 #endif |
6563 * "byte2line(byte)" function | 6495 * "byte2line(byte)" function |
6564 */ | 6496 */ |
6565 /*ARGSUSED*/ | 6497 /*ARGSUSED*/ |
6566 static void | 6498 static void |
6567 f_byte2line(argvars, rettv) | 6499 f_byte2line(argvars, rettv) |
6568 typeval *argvars; | 6500 typval_T *argvars; |
6569 typeval *rettv; | 6501 typval_T *rettv; |
6570 { | 6502 { |
6571 #ifndef FEAT_BYTEOFF | 6503 #ifndef FEAT_BYTEOFF |
6572 rettv->vval.v_number = -1; | 6504 rettv->vval.v_number = -1; |
6573 #else | 6505 #else |
6574 long boff = 0; | 6506 long boff = 0; |
6586 * "byteidx()" function | 6518 * "byteidx()" function |
6587 */ | 6519 */ |
6588 /*ARGSUSED*/ | 6520 /*ARGSUSED*/ |
6589 static void | 6521 static void |
6590 f_byteidx(argvars, rettv) | 6522 f_byteidx(argvars, rettv) |
6591 typeval *argvars; | 6523 typval_T *argvars; |
6592 typeval *rettv; | 6524 typval_T *rettv; |
6593 { | 6525 { |
6594 #ifdef FEAT_MBYTE | 6526 #ifdef FEAT_MBYTE |
6595 char_u *t; | 6527 char_u *t; |
6596 #endif | 6528 #endif |
6597 char_u *str; | 6529 char_u *str; |
6621 /* | 6553 /* |
6622 * "call(func, arglist)" function | 6554 * "call(func, arglist)" function |
6623 */ | 6555 */ |
6624 static void | 6556 static void |
6625 f_call(argvars, rettv) | 6557 f_call(argvars, rettv) |
6626 typeval *argvars; | 6558 typval_T *argvars; |
6627 typeval *rettv; | 6559 typval_T *rettv; |
6628 { | 6560 { |
6629 char_u *func; | 6561 char_u *func; |
6630 typeval argv[MAX_FUNC_ARGS]; | 6562 typval_T argv[MAX_FUNC_ARGS]; |
6631 int argc = 0; | 6563 int argc = 0; |
6632 listitem *item; | 6564 listitem_T *item; |
6633 int dummy; | 6565 int dummy; |
6634 dictvar *selfdict = NULL; | 6566 dict_T *selfdict = NULL; |
6635 | 6567 |
6636 rettv->vval.v_number = 0; | 6568 rettv->vval.v_number = 0; |
6637 if (argvars[1].v_type != VAR_LIST) | 6569 if (argvars[1].v_type != VAR_LIST) |
6638 { | 6570 { |
6639 EMSG(_(e_listreq)); | 6571 EMSG(_(e_listreq)); |
6682 /* | 6614 /* |
6683 * "char2nr(string)" function | 6615 * "char2nr(string)" function |
6684 */ | 6616 */ |
6685 static void | 6617 static void |
6686 f_char2nr(argvars, rettv) | 6618 f_char2nr(argvars, rettv) |
6687 typeval *argvars; | 6619 typval_T *argvars; |
6688 typeval *rettv; | 6620 typval_T *rettv; |
6689 { | 6621 { |
6690 #ifdef FEAT_MBYTE | 6622 #ifdef FEAT_MBYTE |
6691 if (has_mbyte) | 6623 if (has_mbyte) |
6692 rettv->vval.v_number = | 6624 rettv->vval.v_number = |
6693 (*mb_ptr2char)(get_tv_string(&argvars[0])); | 6625 (*mb_ptr2char)(get_tv_string(&argvars[0])); |
6699 /* | 6631 /* |
6700 * "cindent(lnum)" function | 6632 * "cindent(lnum)" function |
6701 */ | 6633 */ |
6702 static void | 6634 static void |
6703 f_cindent(argvars, rettv) | 6635 f_cindent(argvars, rettv) |
6704 typeval *argvars; | 6636 typval_T *argvars; |
6705 typeval *rettv; | 6637 typval_T *rettv; |
6706 { | 6638 { |
6707 #ifdef FEAT_CINDENT | 6639 #ifdef FEAT_CINDENT |
6708 pos_T pos; | 6640 pos_T pos; |
6709 linenr_T lnum; | 6641 linenr_T lnum; |
6710 | 6642 |
6724 /* | 6656 /* |
6725 * "col(string)" function | 6657 * "col(string)" function |
6726 */ | 6658 */ |
6727 static void | 6659 static void |
6728 f_col(argvars, rettv) | 6660 f_col(argvars, rettv) |
6729 typeval *argvars; | 6661 typval_T *argvars; |
6730 typeval *rettv; | 6662 typval_T *rettv; |
6731 { | 6663 { |
6732 colnr_T col = 0; | 6664 colnr_T col = 0; |
6733 pos_T *fp; | 6665 pos_T *fp; |
6734 | 6666 |
6735 fp = var2fpos(&argvars[0], FALSE); | 6667 fp = var2fpos(&argvars[0], FALSE); |
6777 * "confirm(message, buttons[, default [, type]])" function | 6709 * "confirm(message, buttons[, default [, type]])" function |
6778 */ | 6710 */ |
6779 /*ARGSUSED*/ | 6711 /*ARGSUSED*/ |
6780 static void | 6712 static void |
6781 f_confirm(argvars, rettv) | 6713 f_confirm(argvars, rettv) |
6782 typeval *argvars; | 6714 typval_T *argvars; |
6783 typeval *rettv; | 6715 typval_T *rettv; |
6784 { | 6716 { |
6785 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | 6717 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
6786 char_u *message; | 6718 char_u *message; |
6787 char_u *buttons = NULL; | 6719 char_u *buttons = NULL; |
6788 char_u buf[NUMBUFLEN]; | 6720 char_u buf[NUMBUFLEN]; |
6827 /* | 6759 /* |
6828 * "copy()" function | 6760 * "copy()" function |
6829 */ | 6761 */ |
6830 static void | 6762 static void |
6831 f_copy(argvars, rettv) | 6763 f_copy(argvars, rettv) |
6832 typeval *argvars; | 6764 typval_T *argvars; |
6833 typeval *rettv; | 6765 typval_T *rettv; |
6834 { | 6766 { |
6835 item_copy(&argvars[0], rettv, FALSE); | 6767 item_copy(&argvars[0], rettv, FALSE); |
6836 } | 6768 } |
6837 | 6769 |
6838 /* | 6770 /* |
6839 * "count()" function | 6771 * "count()" function |
6840 */ | 6772 */ |
6841 static void | 6773 static void |
6842 f_count(argvars, rettv) | 6774 f_count(argvars, rettv) |
6843 typeval *argvars; | 6775 typval_T *argvars; |
6844 typeval *rettv; | 6776 typval_T *rettv; |
6845 { | 6777 { |
6846 long n = 0; | 6778 long n = 0; |
6847 int ic = FALSE; | 6779 int ic = FALSE; |
6848 | 6780 |
6849 if (argvars[0].v_type == VAR_LIST) | 6781 if (argvars[0].v_type == VAR_LIST) |
6850 { | 6782 { |
6851 listitem *li; | 6783 listitem_T *li; |
6852 listvar *l; | 6784 list_T *l; |
6853 long idx; | 6785 long idx; |
6854 | 6786 |
6855 if ((l = argvars[0].vval.v_list) != NULL) | 6787 if ((l = argvars[0].vval.v_list) != NULL) |
6856 { | 6788 { |
6857 li = l->lv_first; | 6789 li = l->lv_first; |
6872 ++n; | 6804 ++n; |
6873 } | 6805 } |
6874 } | 6806 } |
6875 else if (argvars[0].v_type == VAR_DICT) | 6807 else if (argvars[0].v_type == VAR_DICT) |
6876 { | 6808 { |
6877 int todo; | 6809 int todo; |
6878 dictvar *d; | 6810 dict_T *d; |
6879 hashitem *hi; | 6811 hashitem_T *hi; |
6880 | 6812 |
6881 if ((d = argvars[0].vval.v_dict) != NULL) | 6813 if ((d = argvars[0].vval.v_dict) != NULL) |
6882 { | 6814 { |
6883 if (argvars[2].v_type != VAR_UNKNOWN) | 6815 if (argvars[2].v_type != VAR_UNKNOWN) |
6884 { | 6816 { |
6885 ic = get_tv_number(&argvars[2]); | 6817 ic = get_tv_number(&argvars[2]); |
6886 if (argvars[3].v_type != VAR_UNKNOWN) | 6818 if (argvars[3].v_type != VAR_UNKNOWN) |
6887 EMSG(_(e_invarg)); | 6819 EMSG(_(e_invarg)); |
6888 } | 6820 } |
6889 | 6821 |
6890 todo = d->dv_hashtable.ht_used; | 6822 todo = d->dv_hashtab.ht_used; |
6891 for (hi = d->dv_hashtable.ht_array; todo > 0; ++hi) | 6823 for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) |
6892 { | 6824 { |
6893 if (!HASHITEM_EMPTY(hi)) | 6825 if (!HASHITEM_EMPTY(hi)) |
6894 { | 6826 { |
6895 --todo; | 6827 --todo; |
6896 if (tv_equal(&HI2DI(hi)->di_tv, &argvars[1], ic)) | 6828 if (tv_equal(&HI2DI(hi)->di_tv, &argvars[1], ic)) |
6910 * Checks the existence of a cscope connection. | 6842 * Checks the existence of a cscope connection. |
6911 */ | 6843 */ |
6912 /*ARGSUSED*/ | 6844 /*ARGSUSED*/ |
6913 static void | 6845 static void |
6914 f_cscope_connection(argvars, rettv) | 6846 f_cscope_connection(argvars, rettv) |
6915 typeval *argvars; | 6847 typval_T *argvars; |
6916 typeval *rettv; | 6848 typval_T *rettv; |
6917 { | 6849 { |
6918 #ifdef FEAT_CSCOPE | 6850 #ifdef FEAT_CSCOPE |
6919 int num = 0; | 6851 int num = 0; |
6920 char_u *dbpath = NULL; | 6852 char_u *dbpath = NULL; |
6921 char_u *prepend = NULL; | 6853 char_u *prepend = NULL; |
6942 * Moves the cursor to the specified line and column | 6874 * Moves the cursor to the specified line and column |
6943 */ | 6875 */ |
6944 /*ARGSUSED*/ | 6876 /*ARGSUSED*/ |
6945 static void | 6877 static void |
6946 f_cursor(argvars, rettv) | 6878 f_cursor(argvars, rettv) |
6947 typeval *argvars; | 6879 typval_T *argvars; |
6948 typeval *rettv; | 6880 typval_T *rettv; |
6949 { | 6881 { |
6950 long line, col; | 6882 long line, col; |
6951 | 6883 |
6952 line = get_tv_lnum(argvars); | 6884 line = get_tv_lnum(argvars); |
6953 if (line > 0) | 6885 if (line > 0) |
6973 /* | 6905 /* |
6974 * "deepcopy()" function | 6906 * "deepcopy()" function |
6975 */ | 6907 */ |
6976 static void | 6908 static void |
6977 f_deepcopy(argvars, rettv) | 6909 f_deepcopy(argvars, rettv) |
6978 typeval *argvars; | 6910 typval_T *argvars; |
6979 typeval *rettv; | 6911 typval_T *rettv; |
6980 { | 6912 { |
6981 item_copy(&argvars[0], rettv, TRUE); | 6913 item_copy(&argvars[0], rettv, TRUE); |
6982 } | 6914 } |
6983 | 6915 |
6984 /* | 6916 /* |
6985 * "delete()" function | 6917 * "delete()" function |
6986 */ | 6918 */ |
6987 static void | 6919 static void |
6988 f_delete(argvars, rettv) | 6920 f_delete(argvars, rettv) |
6989 typeval *argvars; | 6921 typval_T *argvars; |
6990 typeval *rettv; | 6922 typval_T *rettv; |
6991 { | 6923 { |
6992 if (check_restricted() || check_secure()) | 6924 if (check_restricted() || check_secure()) |
6993 rettv->vval.v_number = -1; | 6925 rettv->vval.v_number = -1; |
6994 else | 6926 else |
6995 rettv->vval.v_number = mch_remove(get_tv_string(&argvars[0])); | 6927 rettv->vval.v_number = mch_remove(get_tv_string(&argvars[0])); |
6999 * "did_filetype()" function | 6931 * "did_filetype()" function |
7000 */ | 6932 */ |
7001 /*ARGSUSED*/ | 6933 /*ARGSUSED*/ |
7002 static void | 6934 static void |
7003 f_did_filetype(argvars, rettv) | 6935 f_did_filetype(argvars, rettv) |
7004 typeval *argvars; | 6936 typval_T *argvars; |
7005 typeval *rettv; | 6937 typval_T *rettv; |
7006 { | 6938 { |
7007 #ifdef FEAT_AUTOCMD | 6939 #ifdef FEAT_AUTOCMD |
7008 rettv->vval.v_number = did_filetype; | 6940 rettv->vval.v_number = did_filetype; |
7009 #else | 6941 #else |
7010 rettv->vval.v_number = 0; | 6942 rettv->vval.v_number = 0; |
7015 * "diff_filler()" function | 6947 * "diff_filler()" function |
7016 */ | 6948 */ |
7017 /*ARGSUSED*/ | 6949 /*ARGSUSED*/ |
7018 static void | 6950 static void |
7019 f_diff_filler(argvars, rettv) | 6951 f_diff_filler(argvars, rettv) |
7020 typeval *argvars; | 6952 typval_T *argvars; |
7021 typeval *rettv; | 6953 typval_T *rettv; |
7022 { | 6954 { |
7023 #ifdef FEAT_DIFF | 6955 #ifdef FEAT_DIFF |
7024 rettv->vval.v_number = diff_check_fill(curwin, get_tv_lnum(argvars)); | 6956 rettv->vval.v_number = diff_check_fill(curwin, get_tv_lnum(argvars)); |
7025 #endif | 6957 #endif |
7026 } | 6958 } |
7029 * "diff_hlID()" function | 6961 * "diff_hlID()" function |
7030 */ | 6962 */ |
7031 /*ARGSUSED*/ | 6963 /*ARGSUSED*/ |
7032 static void | 6964 static void |
7033 f_diff_hlID(argvars, rettv) | 6965 f_diff_hlID(argvars, rettv) |
7034 typeval *argvars; | 6966 typval_T *argvars; |
7035 typeval *rettv; | 6967 typval_T *rettv; |
7036 { | 6968 { |
7037 #ifdef FEAT_DIFF | 6969 #ifdef FEAT_DIFF |
7038 linenr_T lnum = get_tv_lnum(argvars); | 6970 linenr_T lnum = get_tv_lnum(argvars); |
7039 static linenr_T prev_lnum = 0; | 6971 static linenr_T prev_lnum = 0; |
7040 static int changedtick = 0; | 6972 static int changedtick = 0; |
7087 /* | 7019 /* |
7088 * "empty({expr})" function | 7020 * "empty({expr})" function |
7089 */ | 7021 */ |
7090 static void | 7022 static void |
7091 f_empty(argvars, rettv) | 7023 f_empty(argvars, rettv) |
7092 typeval *argvars; | 7024 typval_T *argvars; |
7093 typeval *rettv; | 7025 typval_T *rettv; |
7094 { | 7026 { |
7095 int n; | 7027 int n; |
7096 | 7028 |
7097 switch (argvars[0].v_type) | 7029 switch (argvars[0].v_type) |
7098 { | 7030 { |
7108 n = argvars[0].vval.v_list == NULL | 7040 n = argvars[0].vval.v_list == NULL |
7109 || argvars[0].vval.v_list->lv_first == NULL; | 7041 || argvars[0].vval.v_list->lv_first == NULL; |
7110 break; | 7042 break; |
7111 case VAR_DICT: | 7043 case VAR_DICT: |
7112 n = argvars[0].vval.v_dict == NULL | 7044 n = argvars[0].vval.v_dict == NULL |
7113 || argvars[0].vval.v_dict->dv_hashtable.ht_used == 0; | 7045 || argvars[0].vval.v_dict->dv_hashtab.ht_used == 0; |
7114 break; | 7046 break; |
7115 default: | 7047 default: |
7116 EMSG2(_(e_intern2), "f_empty()"); | 7048 EMSG2(_(e_intern2), "f_empty()"); |
7117 n = 0; | 7049 n = 0; |
7118 } | 7050 } |
7123 /* | 7055 /* |
7124 * "escape({string}, {chars})" function | 7056 * "escape({string}, {chars})" function |
7125 */ | 7057 */ |
7126 static void | 7058 static void |
7127 f_escape(argvars, rettv) | 7059 f_escape(argvars, rettv) |
7128 typeval *argvars; | 7060 typval_T *argvars; |
7129 typeval *rettv; | 7061 typval_T *rettv; |
7130 { | 7062 { |
7131 char_u buf[NUMBUFLEN]; | 7063 char_u buf[NUMBUFLEN]; |
7132 | 7064 |
7133 rettv->vval.v_string = | 7065 rettv->vval.v_string = |
7134 vim_strsave_escaped(get_tv_string(&argvars[0]), | 7066 vim_strsave_escaped(get_tv_string(&argvars[0]), |
7140 * "eval()" function | 7072 * "eval()" function |
7141 */ | 7073 */ |
7142 /*ARGSUSED*/ | 7074 /*ARGSUSED*/ |
7143 static void | 7075 static void |
7144 f_eval(argvars, rettv) | 7076 f_eval(argvars, rettv) |
7145 typeval *argvars; | 7077 typval_T *argvars; |
7146 typeval *rettv; | 7078 typval_T *rettv; |
7147 { | 7079 { |
7148 char_u *s; | 7080 char_u *s; |
7149 | 7081 |
7150 s = get_tv_string(&argvars[0]); | 7082 s = get_tv_string(&argvars[0]); |
7151 s = skipwhite(s); | 7083 s = skipwhite(s); |
7160 * "eventhandler()" function | 7092 * "eventhandler()" function |
7161 */ | 7093 */ |
7162 /*ARGSUSED*/ | 7094 /*ARGSUSED*/ |
7163 static void | 7095 static void |
7164 f_eventhandler(argvars, rettv) | 7096 f_eventhandler(argvars, rettv) |
7165 typeval *argvars; | 7097 typval_T *argvars; |
7166 typeval *rettv; | 7098 typval_T *rettv; |
7167 { | 7099 { |
7168 rettv->vval.v_number = vgetc_busy; | 7100 rettv->vval.v_number = vgetc_busy; |
7169 } | 7101 } |
7170 | 7102 |
7171 /* | 7103 /* |
7172 * "executable()" function | 7104 * "executable()" function |
7173 */ | 7105 */ |
7174 static void | 7106 static void |
7175 f_executable(argvars, rettv) | 7107 f_executable(argvars, rettv) |
7176 typeval *argvars; | 7108 typval_T *argvars; |
7177 typeval *rettv; | 7109 typval_T *rettv; |
7178 { | 7110 { |
7179 rettv->vval.v_number = mch_can_exe(get_tv_string(&argvars[0])); | 7111 rettv->vval.v_number = mch_can_exe(get_tv_string(&argvars[0])); |
7180 } | 7112 } |
7181 | 7113 |
7182 /* | 7114 /* |
7183 * "exists()" function | 7115 * "exists()" function |
7184 */ | 7116 */ |
7185 static void | 7117 static void |
7186 f_exists(argvars, rettv) | 7118 f_exists(argvars, rettv) |
7187 typeval *argvars; | 7119 typval_T *argvars; |
7188 typeval *rettv; | 7120 typval_T *rettv; |
7189 { | 7121 { |
7190 char_u *p; | 7122 char_u *p; |
7191 char_u *name; | 7123 char_u *name; |
7192 int n = FALSE; | 7124 int n = FALSE; |
7193 int len = 0; | 7125 int len = 0; |
7261 /* | 7193 /* |
7262 * "expand()" function | 7194 * "expand()" function |
7263 */ | 7195 */ |
7264 static void | 7196 static void |
7265 f_expand(argvars, rettv) | 7197 f_expand(argvars, rettv) |
7266 typeval *argvars; | 7198 typval_T *argvars; |
7267 typeval *rettv; | 7199 typval_T *rettv; |
7268 { | 7200 { |
7269 char_u *s; | 7201 char_u *s; |
7270 int len; | 7202 int len; |
7271 char_u *errormsg; | 7203 char_u *errormsg; |
7272 int flags = WILD_SILENT|WILD_USE_NL|WILD_LIST_NOTFOUND; | 7204 int flags = WILD_SILENT|WILD_USE_NL|WILD_LIST_NOTFOUND; |
7297 * "extend(list, list [, idx])" function | 7229 * "extend(list, list [, idx])" function |
7298 * "extend(dict, dict [, action])" function | 7230 * "extend(dict, dict [, action])" function |
7299 */ | 7231 */ |
7300 static void | 7232 static void |
7301 f_extend(argvars, rettv) | 7233 f_extend(argvars, rettv) |
7302 typeval *argvars; | 7234 typval_T *argvars; |
7303 typeval *rettv; | 7235 typval_T *rettv; |
7304 { | 7236 { |
7305 rettv->vval.v_number = 0; | 7237 rettv->vval.v_number = 0; |
7306 if (argvars[0].v_type == VAR_LIST && argvars[1].v_type == VAR_LIST) | 7238 if (argvars[0].v_type == VAR_LIST && argvars[1].v_type == VAR_LIST) |
7307 { | 7239 { |
7308 listvar *l1, *l2; | 7240 list_T *l1, *l2; |
7309 listitem *item; | 7241 listitem_T *item; |
7310 long before; | 7242 long before; |
7311 long n; | 7243 long n; |
7312 | 7244 |
7313 l1 = argvars[0].vval.v_list; | 7245 l1 = argvars[0].vval.v_list; |
7314 l2 = argvars[1].vval.v_list; | 7246 l2 = argvars[1].vval.v_list; |
7332 copy_tv(&argvars[0], rettv); | 7264 copy_tv(&argvars[0], rettv); |
7333 } | 7265 } |
7334 } | 7266 } |
7335 else if (argvars[0].v_type == VAR_DICT && argvars[1].v_type == VAR_DICT) | 7267 else if (argvars[0].v_type == VAR_DICT && argvars[1].v_type == VAR_DICT) |
7336 { | 7268 { |
7337 dictvar *d1, *d2; | 7269 dict_T *d1, *d2; |
7338 dictitem *di1; | 7270 dictitem_T *di1; |
7339 char_u *action; | 7271 char_u *action; |
7340 int i; | 7272 int i; |
7341 hashitem *hi2; | 7273 hashitem_T *hi2; |
7342 int todo; | 7274 int todo; |
7343 | 7275 |
7344 d1 = argvars[0].vval.v_dict; | 7276 d1 = argvars[0].vval.v_dict; |
7345 d2 = argvars[1].vval.v_dict; | 7277 d2 = argvars[1].vval.v_dict; |
7346 if (d1 != NULL && d2 != NULL) | 7278 if (d1 != NULL && d2 != NULL) |
7363 else | 7295 else |
7364 action = (char_u *)"force"; | 7296 action = (char_u *)"force"; |
7365 | 7297 |
7366 /* Go over all entries in the second dict and add them to the | 7298 /* Go over all entries in the second dict and add them to the |
7367 * first dict. */ | 7299 * first dict. */ |
7368 todo = d2->dv_hashtable.ht_used; | 7300 todo = d2->dv_hashtab.ht_used; |
7369 for (hi2 = d2->dv_hashtable.ht_array; todo > 0; ++hi2) | 7301 for (hi2 = d2->dv_hashtab.ht_array; todo > 0; ++hi2) |
7370 { | 7302 { |
7371 if (!HASHITEM_EMPTY(hi2)) | 7303 if (!HASHITEM_EMPTY(hi2)) |
7372 { | 7304 { |
7373 --todo; | 7305 --todo; |
7374 di1 = dict_find(d1, hi2->hi_key, -1); | 7306 di1 = dict_find(d1, hi2->hi_key, -1); |
7402 /* | 7334 /* |
7403 * "filereadable()" function | 7335 * "filereadable()" function |
7404 */ | 7336 */ |
7405 static void | 7337 static void |
7406 f_filereadable(argvars, rettv) | 7338 f_filereadable(argvars, rettv) |
7407 typeval *argvars; | 7339 typval_T *argvars; |
7408 typeval *rettv; | 7340 typval_T *rettv; |
7409 { | 7341 { |
7410 FILE *fd; | 7342 FILE *fd; |
7411 char_u *p; | 7343 char_u *p; |
7412 int n; | 7344 int n; |
7413 | 7345 |
7427 * return 0 for not writable, 1 for writable file, 2 for a dir which we have | 7359 * return 0 for not writable, 1 for writable file, 2 for a dir which we have |
7428 * rights to write into. | 7360 * rights to write into. |
7429 */ | 7361 */ |
7430 static void | 7362 static void |
7431 f_filewritable(argvars, rettv) | 7363 f_filewritable(argvars, rettv) |
7432 typeval *argvars; | 7364 typval_T *argvars; |
7433 typeval *rettv; | 7365 typval_T *rettv; |
7434 { | 7366 { |
7435 char_u *p; | 7367 char_u *p; |
7436 int retval = 0; | 7368 int retval = 0; |
7437 #if defined(UNIX) || defined(VMS) | 7369 #if defined(UNIX) || defined(VMS) |
7438 int perm = 0; | 7370 int perm = 0; |
7460 ++retval; | 7392 ++retval; |
7461 } | 7393 } |
7462 rettv->vval.v_number = retval; | 7394 rettv->vval.v_number = retval; |
7463 } | 7395 } |
7464 | 7396 |
7465 static void findfilendir __ARGS((typeval *argvars, typeval *rettv, int dir)); | 7397 static void findfilendir __ARGS((typval_T *argvars, typval_T *rettv, int dir)); |
7466 | 7398 |
7467 static void | 7399 static void |
7468 findfilendir(argvars, rettv, dir) | 7400 findfilendir(argvars, rettv, dir) |
7469 typeval *argvars; | 7401 typval_T *argvars; |
7470 typeval *rettv; | 7402 typval_T *rettv; |
7471 int dir; | 7403 int dir; |
7472 { | 7404 { |
7473 #ifdef FEAT_SEARCHPATH | 7405 #ifdef FEAT_SEARCHPATH |
7474 char_u *fname; | 7406 char_u *fname; |
7475 char_u *fresult = NULL; | 7407 char_u *fresult = NULL; |
7505 rettv->vval.v_string = NULL; | 7437 rettv->vval.v_string = NULL; |
7506 #endif | 7438 #endif |
7507 rettv->v_type = VAR_STRING; | 7439 rettv->v_type = VAR_STRING; |
7508 } | 7440 } |
7509 | 7441 |
7510 static void filter_map __ARGS((typeval *argvars, typeval *rettv, int map)); | 7442 static void filter_map __ARGS((typval_T *argvars, typval_T *rettv, int map)); |
7511 static int filter_map_one __ARGS((typeval *tv, char_u *expr, int map, int *remp)); | 7443 static int filter_map_one __ARGS((typval_T *tv, char_u *expr, int map, int *remp)); |
7512 | 7444 |
7513 /* | 7445 /* |
7514 * Implementation of map() and filter(). | 7446 * Implementation of map() and filter(). |
7515 */ | 7447 */ |
7516 static void | 7448 static void |
7517 filter_map(argvars, rettv, map) | 7449 filter_map(argvars, rettv, map) |
7518 typeval *argvars; | 7450 typval_T *argvars; |
7519 typeval *rettv; | 7451 typval_T *rettv; |
7520 int map; | 7452 int map; |
7521 { | 7453 { |
7522 char_u buf[NUMBUFLEN]; | 7454 char_u buf[NUMBUFLEN]; |
7523 char_u *expr; | 7455 char_u *expr; |
7524 listitem *li, *nli; | 7456 listitem_T *li, *nli; |
7525 listvar *l = NULL; | 7457 list_T *l = NULL; |
7526 dictitem *di; | 7458 dictitem_T *di; |
7527 hashtable *ht; | 7459 hashtab_T *ht; |
7528 hashitem *hi; | 7460 hashitem_T *hi; |
7529 dictvar *d = NULL; | 7461 dict_T *d = NULL; |
7530 typeval save_val; | 7462 typval_T save_val; |
7531 typeval save_key; | 7463 typval_T save_key; |
7532 int rem; | 7464 int rem; |
7533 int todo; | 7465 int todo; |
7534 | 7466 |
7535 rettv->vval.v_number = 0; | 7467 rettv->vval.v_number = 0; |
7536 if (argvars[0].v_type == VAR_LIST) | 7468 if (argvars[0].v_type == VAR_LIST) |
7548 EMSG2(_(e_listdictarg), map ? "map()" : "filter()"); | 7480 EMSG2(_(e_listdictarg), map ? "map()" : "filter()"); |
7549 return; | 7481 return; |
7550 } | 7482 } |
7551 | 7483 |
7552 expr = skipwhite(get_tv_string_buf(&argvars[1], buf)); | 7484 expr = skipwhite(get_tv_string_buf(&argvars[1], buf)); |
7553 save_val = vimvars[VV_VAL].tv; | 7485 save_val = vimvars[VV_VAL].vv_tv; |
7554 | 7486 |
7555 if (argvars[0].v_type == VAR_DICT) | 7487 if (argvars[0].v_type == VAR_DICT) |
7556 { | 7488 { |
7557 save_key = vimvars[VV_KEY].tv; | 7489 save_key = vimvars[VV_KEY].vv_tv; |
7558 vimvars[VV_KEY].tv.v_type = VAR_STRING; | 7490 vimvars[VV_KEY].vv_type = VAR_STRING; |
7559 | 7491 |
7560 ht = &d->dv_hashtable; | 7492 ht = &d->dv_hashtab; |
7561 hash_lock(ht); | 7493 hash_lock(ht); |
7562 todo = ht->ht_used; | 7494 todo = ht->ht_used; |
7563 for (hi = ht->ht_array; todo > 0; ++hi) | 7495 for (hi = ht->ht_array; todo > 0; ++hi) |
7564 { | 7496 { |
7565 if (!HASHITEM_EMPTY(hi)) | 7497 if (!HASHITEM_EMPTY(hi)) |
7566 { | 7498 { |
7567 --todo; | 7499 --todo; |
7568 di = HI2DI(hi); | 7500 di = HI2DI(hi); |
7569 vimvars[VV_KEY].tv.vval.v_string = vim_strsave(di->di_key); | 7501 vimvars[VV_KEY].vv_str = vim_strsave(di->di_key); |
7570 if (filter_map_one(&di->di_tv, expr, map, &rem) == FAIL) | 7502 if (filter_map_one(&di->di_tv, expr, map, &rem) == FAIL) |
7571 break; | 7503 break; |
7572 if (!map && rem) | 7504 if (!map && rem) |
7573 dictitem_remove(d, di); | 7505 dictitem_remove(d, di); |
7574 clear_tv(&vimvars[VV_KEY].tv); | 7506 clear_tv(&vimvars[VV_KEY].vv_tv); |
7575 } | 7507 } |
7576 } | 7508 } |
7577 hash_unlock(ht); | 7509 hash_unlock(ht); |
7578 | 7510 |
7579 clear_tv(&vimvars[VV_KEY].tv); | 7511 clear_tv(&vimvars[VV_KEY].vv_tv); |
7580 vimvars[VV_KEY].tv = save_key; | 7512 vimvars[VV_KEY].vv_tv = save_key; |
7581 } | 7513 } |
7582 else | 7514 else |
7583 { | 7515 { |
7584 for (li = l->lv_first; li != NULL; li = nli) | 7516 for (li = l->lv_first; li != NULL; li = nli) |
7585 { | 7517 { |
7589 if (!map && rem) | 7521 if (!map && rem) |
7590 listitem_remove(l, li); | 7522 listitem_remove(l, li); |
7591 } | 7523 } |
7592 } | 7524 } |
7593 | 7525 |
7594 clear_tv(&vimvars[VV_VAL].tv); | 7526 clear_tv(&vimvars[VV_VAL].vv_tv); |
7595 vimvars[VV_VAL].tv = save_val; | 7527 vimvars[VV_VAL].vv_tv = save_val; |
7596 | 7528 |
7597 copy_tv(&argvars[0], rettv); | 7529 copy_tv(&argvars[0], rettv); |
7598 } | 7530 } |
7599 | 7531 |
7600 static int | 7532 static int |
7601 filter_map_one(tv, expr, map, remp) | 7533 filter_map_one(tv, expr, map, remp) |
7602 typeval *tv; | 7534 typval_T *tv; |
7603 char_u *expr; | 7535 char_u *expr; |
7604 int map; | 7536 int map; |
7605 int *remp; | 7537 int *remp; |
7606 { | 7538 { |
7607 typeval rettv; | 7539 typval_T rettv; |
7608 char_u *s; | 7540 char_u *s; |
7609 | 7541 |
7610 copy_tv(tv, &vimvars[VV_VAL].tv); | 7542 copy_tv(tv, &vimvars[VV_VAL].vv_tv); |
7611 s = expr; | 7543 s = expr; |
7612 if (eval1(&s, &rettv, TRUE) == FAIL) | 7544 if (eval1(&s, &rettv, TRUE) == FAIL) |
7613 return FAIL; | 7545 return FAIL; |
7614 if (*s != NUL) /* check for trailing chars after expr */ | 7546 if (*s != NUL) /* check for trailing chars after expr */ |
7615 { | 7547 { |
7626 { | 7558 { |
7627 /* filter(): when expr is zero remove the item */ | 7559 /* filter(): when expr is zero remove the item */ |
7628 *remp = (get_tv_number(&rettv) == 0); | 7560 *remp = (get_tv_number(&rettv) == 0); |
7629 clear_tv(&rettv); | 7561 clear_tv(&rettv); |
7630 } | 7562 } |
7631 clear_tv(&vimvars[VV_VAL].tv); | 7563 clear_tv(&vimvars[VV_VAL].vv_tv); |
7632 return OK; | 7564 return OK; |
7633 } | 7565 } |
7634 | 7566 |
7635 /* | 7567 /* |
7636 * "filter()" function | 7568 * "filter()" function |
7637 */ | 7569 */ |
7638 static void | 7570 static void |
7639 f_filter(argvars, rettv) | 7571 f_filter(argvars, rettv) |
7640 typeval *argvars; | 7572 typval_T *argvars; |
7641 typeval *rettv; | 7573 typval_T *rettv; |
7642 { | 7574 { |
7643 filter_map(argvars, rettv, FALSE); | 7575 filter_map(argvars, rettv, FALSE); |
7644 } | 7576 } |
7645 | 7577 |
7646 /* | 7578 /* |
7647 * "finddir({fname}[, {path}[, {count}]])" function | 7579 * "finddir({fname}[, {path}[, {count}]])" function |
7648 */ | 7580 */ |
7649 static void | 7581 static void |
7650 f_finddir(argvars, rettv) | 7582 f_finddir(argvars, rettv) |
7651 typeval *argvars; | 7583 typval_T *argvars; |
7652 typeval *rettv; | 7584 typval_T *rettv; |
7653 { | 7585 { |
7654 findfilendir(argvars, rettv, TRUE); | 7586 findfilendir(argvars, rettv, TRUE); |
7655 } | 7587 } |
7656 | 7588 |
7657 /* | 7589 /* |
7658 * "findfile({fname}[, {path}[, {count}]])" function | 7590 * "findfile({fname}[, {path}[, {count}]])" function |
7659 */ | 7591 */ |
7660 static void | 7592 static void |
7661 f_findfile(argvars, rettv) | 7593 f_findfile(argvars, rettv) |
7662 typeval *argvars; | 7594 typval_T *argvars; |
7663 typeval *rettv; | 7595 typval_T *rettv; |
7664 { | 7596 { |
7665 findfilendir(argvars, rettv, FALSE); | 7597 findfilendir(argvars, rettv, FALSE); |
7666 } | 7598 } |
7667 | 7599 |
7668 /* | 7600 /* |
7669 * "fnamemodify({fname}, {mods})" function | 7601 * "fnamemodify({fname}, {mods})" function |
7670 */ | 7602 */ |
7671 static void | 7603 static void |
7672 f_fnamemodify(argvars, rettv) | 7604 f_fnamemodify(argvars, rettv) |
7673 typeval *argvars; | 7605 typval_T *argvars; |
7674 typeval *rettv; | 7606 typval_T *rettv; |
7675 { | 7607 { |
7676 char_u *fname; | 7608 char_u *fname; |
7677 char_u *mods; | 7609 char_u *mods; |
7678 int usedlen = 0; | 7610 int usedlen = 0; |
7679 int len; | 7611 int len; |
7692 else | 7624 else |
7693 rettv->vval.v_string = vim_strnsave(fname, len); | 7625 rettv->vval.v_string = vim_strnsave(fname, len); |
7694 vim_free(fbuf); | 7626 vim_free(fbuf); |
7695 } | 7627 } |
7696 | 7628 |
7697 static void foldclosed_both __ARGS((typeval *argvars, typeval *rettv, int end)); | 7629 static void foldclosed_both __ARGS((typval_T *argvars, typval_T *rettv, int end)); |
7698 | 7630 |
7699 /* | 7631 /* |
7700 * "foldclosed()" function | 7632 * "foldclosed()" function |
7701 */ | 7633 */ |
7702 static void | 7634 static void |
7703 foldclosed_both(argvars, rettv, end) | 7635 foldclosed_both(argvars, rettv, end) |
7704 typeval *argvars; | 7636 typval_T *argvars; |
7705 typeval *rettv; | 7637 typval_T *rettv; |
7706 int end; | 7638 int end; |
7707 { | 7639 { |
7708 #ifdef FEAT_FOLDING | 7640 #ifdef FEAT_FOLDING |
7709 linenr_T lnum; | 7641 linenr_T lnum; |
7710 linenr_T first, last; | 7642 linenr_T first, last; |
7728 /* | 7660 /* |
7729 * "foldclosed()" function | 7661 * "foldclosed()" function |
7730 */ | 7662 */ |
7731 static void | 7663 static void |
7732 f_foldclosed(argvars, rettv) | 7664 f_foldclosed(argvars, rettv) |
7733 typeval *argvars; | 7665 typval_T *argvars; |
7734 typeval *rettv; | 7666 typval_T *rettv; |
7735 { | 7667 { |
7736 foldclosed_both(argvars, rettv, FALSE); | 7668 foldclosed_both(argvars, rettv, FALSE); |
7737 } | 7669 } |
7738 | 7670 |
7739 /* | 7671 /* |
7740 * "foldclosedend()" function | 7672 * "foldclosedend()" function |
7741 */ | 7673 */ |
7742 static void | 7674 static void |
7743 f_foldclosedend(argvars, rettv) | 7675 f_foldclosedend(argvars, rettv) |
7744 typeval *argvars; | 7676 typval_T *argvars; |
7745 typeval *rettv; | 7677 typval_T *rettv; |
7746 { | 7678 { |
7747 foldclosed_both(argvars, rettv, TRUE); | 7679 foldclosed_both(argvars, rettv, TRUE); |
7748 } | 7680 } |
7749 | 7681 |
7750 /* | 7682 /* |
7751 * "foldlevel()" function | 7683 * "foldlevel()" function |
7752 */ | 7684 */ |
7753 static void | 7685 static void |
7754 f_foldlevel(argvars, rettv) | 7686 f_foldlevel(argvars, rettv) |
7755 typeval *argvars; | 7687 typval_T *argvars; |
7756 typeval *rettv; | 7688 typval_T *rettv; |
7757 { | 7689 { |
7758 #ifdef FEAT_FOLDING | 7690 #ifdef FEAT_FOLDING |
7759 linenr_T lnum; | 7691 linenr_T lnum; |
7760 | 7692 |
7761 lnum = get_tv_lnum(argvars); | 7693 lnum = get_tv_lnum(argvars); |
7770 * "foldtext()" function | 7702 * "foldtext()" function |
7771 */ | 7703 */ |
7772 /*ARGSUSED*/ | 7704 /*ARGSUSED*/ |
7773 static void | 7705 static void |
7774 f_foldtext(argvars, rettv) | 7706 f_foldtext(argvars, rettv) |
7775 typeval *argvars; | 7707 typval_T *argvars; |
7776 typeval *rettv; | 7708 typval_T *rettv; |
7777 { | 7709 { |
7778 #ifdef FEAT_FOLDING | 7710 #ifdef FEAT_FOLDING |
7779 linenr_T lnum; | 7711 linenr_T lnum; |
7780 char_u *s; | 7712 char_u *s; |
7781 char_u *r; | 7713 char_u *r; |
7838 * "foldtextresult(lnum)" function | 7770 * "foldtextresult(lnum)" function |
7839 */ | 7771 */ |
7840 /*ARGSUSED*/ | 7772 /*ARGSUSED*/ |
7841 static void | 7773 static void |
7842 f_foldtextresult(argvars, rettv) | 7774 f_foldtextresult(argvars, rettv) |
7843 typeval *argvars; | 7775 typval_T *argvars; |
7844 typeval *rettv; | 7776 typval_T *rettv; |
7845 { | 7777 { |
7846 #ifdef FEAT_FOLDING | 7778 #ifdef FEAT_FOLDING |
7847 linenr_T lnum; | 7779 linenr_T lnum; |
7848 char_u *text; | 7780 char_u *text; |
7849 char_u buf[51]; | 7781 char_u buf[51]; |
7871 * "foreground()" function | 7803 * "foreground()" function |
7872 */ | 7804 */ |
7873 /*ARGSUSED*/ | 7805 /*ARGSUSED*/ |
7874 static void | 7806 static void |
7875 f_foreground(argvars, rettv) | 7807 f_foreground(argvars, rettv) |
7876 typeval *argvars; | 7808 typval_T *argvars; |
7877 typeval *rettv; | 7809 typval_T *rettv; |
7878 { | 7810 { |
7879 rettv->vval.v_number = 0; | 7811 rettv->vval.v_number = 0; |
7880 #ifdef FEAT_GUI | 7812 #ifdef FEAT_GUI |
7881 if (gui.in_use) | 7813 if (gui.in_use) |
7882 gui_mch_set_foreground(); | 7814 gui_mch_set_foreground(); |
7891 * "function()" function | 7823 * "function()" function |
7892 */ | 7824 */ |
7893 /*ARGSUSED*/ | 7825 /*ARGSUSED*/ |
7894 static void | 7826 static void |
7895 f_function(argvars, rettv) | 7827 f_function(argvars, rettv) |
7896 typeval *argvars; | 7828 typval_T *argvars; |
7897 typeval *rettv; | 7829 typval_T *rettv; |
7898 { | 7830 { |
7899 char_u *s; | 7831 char_u *s; |
7900 | 7832 |
7901 rettv->vval.v_number = 0; | 7833 rettv->vval.v_number = 0; |
7902 s = get_tv_string(&argvars[0]); | 7834 s = get_tv_string(&argvars[0]); |
7914 /* | 7846 /* |
7915 * "get()" function | 7847 * "get()" function |
7916 */ | 7848 */ |
7917 static void | 7849 static void |
7918 f_get(argvars, rettv) | 7850 f_get(argvars, rettv) |
7919 typeval *argvars; | 7851 typval_T *argvars; |
7920 typeval *rettv; | 7852 typval_T *rettv; |
7921 { | 7853 { |
7922 listitem *li; | 7854 listitem_T *li; |
7923 listvar *l; | 7855 list_T *l; |
7924 dictitem *di; | 7856 dictitem_T *di; |
7925 dictvar *d; | 7857 dict_T *d; |
7926 typeval *tv = NULL; | 7858 typval_T *tv = NULL; |
7927 | 7859 |
7928 if (argvars[0].v_type == VAR_LIST) | 7860 if (argvars[0].v_type == VAR_LIST) |
7929 { | 7861 { |
7930 if ((l = argvars[0].vval.v_list) != NULL) | 7862 if ((l = argvars[0].vval.v_list) != NULL) |
7931 { | 7863 { |
7960 /* | 7892 /* |
7961 * "getbufvar()" function | 7893 * "getbufvar()" function |
7962 */ | 7894 */ |
7963 static void | 7895 static void |
7964 f_getbufvar(argvars, rettv) | 7896 f_getbufvar(argvars, rettv) |
7965 typeval *argvars; | 7897 typval_T *argvars; |
7966 typeval *rettv; | 7898 typval_T *rettv; |
7967 { | 7899 { |
7968 buf_T *buf; | 7900 buf_T *buf; |
7969 buf_T *save_curbuf; | 7901 buf_T *save_curbuf; |
7970 char_u *varname; | 7902 char_u *varname; |
7971 VAR v; | 7903 dictitem_T *v; |
7972 | 7904 |
7973 ++emsg_off; | 7905 ++emsg_off; |
7974 buf = get_buf_tv(&argvars[0]); | 7906 buf = get_buf_tv(&argvars[0]); |
7975 varname = get_tv_string(&argvars[1]); | 7907 varname = get_tv_string(&argvars[1]); |
7976 | 7908 |
7991 curbuf = save_curbuf; | 7923 curbuf = save_curbuf; |
7992 } | 7924 } |
7993 else | 7925 else |
7994 { | 7926 { |
7995 /* look up the variable */ | 7927 /* look up the variable */ |
7996 v = find_var_in_ht(&buf->b_vars, varname); | 7928 v = find_var_in_ht(&buf->b_vars.dv_hashtab, varname); |
7997 if (v != NULL) | 7929 if (v != NULL) |
7998 copy_tv(&v->tv, rettv); | 7930 copy_tv(&v->di_tv, rettv); |
7999 } | 7931 } |
8000 } | 7932 } |
8001 | 7933 |
8002 --emsg_off; | 7934 --emsg_off; |
8003 } | 7935 } |
8005 /* | 7937 /* |
8006 * "getchar()" function | 7938 * "getchar()" function |
8007 */ | 7939 */ |
8008 static void | 7940 static void |
8009 f_getchar(argvars, rettv) | 7941 f_getchar(argvars, rettv) |
8010 typeval *argvars; | 7942 typval_T *argvars; |
8011 typeval *rettv; | 7943 typval_T *rettv; |
8012 { | 7944 { |
8013 varnumber_T n; | 7945 varnumber_T n; |
8014 | 7946 |
8015 ++no_mapping; | 7947 ++no_mapping; |
8016 ++allow_keys; | 7948 ++allow_keys; |
8064 * "getcharmod()" function | 7996 * "getcharmod()" function |
8065 */ | 7997 */ |
8066 /*ARGSUSED*/ | 7998 /*ARGSUSED*/ |
8067 static void | 7999 static void |
8068 f_getcharmod(argvars, rettv) | 8000 f_getcharmod(argvars, rettv) |
8069 typeval *argvars; | 8001 typval_T *argvars; |
8070 typeval *rettv; | 8002 typval_T *rettv; |
8071 { | 8003 { |
8072 rettv->vval.v_number = mod_mask; | 8004 rettv->vval.v_number = mod_mask; |
8073 } | 8005 } |
8074 | 8006 |
8075 /* | 8007 /* |
8076 * "getcmdline()" function | 8008 * "getcmdline()" function |
8077 */ | 8009 */ |
8078 /*ARGSUSED*/ | 8010 /*ARGSUSED*/ |
8079 static void | 8011 static void |
8080 f_getcmdline(argvars, rettv) | 8012 f_getcmdline(argvars, rettv) |
8081 typeval *argvars; | 8013 typval_T *argvars; |
8082 typeval *rettv; | 8014 typval_T *rettv; |
8083 { | 8015 { |
8084 rettv->v_type = VAR_STRING; | 8016 rettv->v_type = VAR_STRING; |
8085 rettv->vval.v_string = get_cmdline_str(); | 8017 rettv->vval.v_string = get_cmdline_str(); |
8086 } | 8018 } |
8087 | 8019 |
8089 * "getcmdpos()" function | 8021 * "getcmdpos()" function |
8090 */ | 8022 */ |
8091 /*ARGSUSED*/ | 8023 /*ARGSUSED*/ |
8092 static void | 8024 static void |
8093 f_getcmdpos(argvars, rettv) | 8025 f_getcmdpos(argvars, rettv) |
8094 typeval *argvars; | 8026 typval_T *argvars; |
8095 typeval *rettv; | 8027 typval_T *rettv; |
8096 { | 8028 { |
8097 rettv->vval.v_number = get_cmdline_pos() + 1; | 8029 rettv->vval.v_number = get_cmdline_pos() + 1; |
8098 } | 8030 } |
8099 | 8031 |
8100 /* | 8032 /* |
8101 * "getcwd()" function | 8033 * "getcwd()" function |
8102 */ | 8034 */ |
8103 /*ARGSUSED*/ | 8035 /*ARGSUSED*/ |
8104 static void | 8036 static void |
8105 f_getcwd(argvars, rettv) | 8037 f_getcwd(argvars, rettv) |
8106 typeval *argvars; | 8038 typval_T *argvars; |
8107 typeval *rettv; | 8039 typval_T *rettv; |
8108 { | 8040 { |
8109 char_u cwd[MAXPATHL]; | 8041 char_u cwd[MAXPATHL]; |
8110 | 8042 |
8111 rettv->v_type = VAR_STRING; | 8043 rettv->v_type = VAR_STRING; |
8112 if (mch_dirname(cwd, MAXPATHL) == FAIL) | 8044 if (mch_dirname(cwd, MAXPATHL) == FAIL) |
8124 * "getfontname()" function | 8056 * "getfontname()" function |
8125 */ | 8057 */ |
8126 /*ARGSUSED*/ | 8058 /*ARGSUSED*/ |
8127 static void | 8059 static void |
8128 f_getfontname(argvars, rettv) | 8060 f_getfontname(argvars, rettv) |
8129 typeval *argvars; | 8061 typval_T *argvars; |
8130 typeval *rettv; | 8062 typval_T *rettv; |
8131 { | 8063 { |
8132 rettv->v_type = VAR_STRING; | 8064 rettv->v_type = VAR_STRING; |
8133 rettv->vval.v_string = NULL; | 8065 rettv->vval.v_string = NULL; |
8134 #ifdef FEAT_GUI | 8066 #ifdef FEAT_GUI |
8135 if (gui.in_use) | 8067 if (gui.in_use) |
8163 /* | 8095 /* |
8164 * "getfperm({fname})" function | 8096 * "getfperm({fname})" function |
8165 */ | 8097 */ |
8166 static void | 8098 static void |
8167 f_getfperm(argvars, rettv) | 8099 f_getfperm(argvars, rettv) |
8168 typeval *argvars; | 8100 typval_T *argvars; |
8169 typeval *rettv; | 8101 typval_T *rettv; |
8170 { | 8102 { |
8171 char_u *fname; | 8103 char_u *fname; |
8172 struct stat st; | 8104 struct stat st; |
8173 char_u *perm = NULL; | 8105 char_u *perm = NULL; |
8174 char_u flags[] = "rwx"; | 8106 char_u flags[] = "rwx"; |
8195 /* | 8127 /* |
8196 * "getfsize({fname})" function | 8128 * "getfsize({fname})" function |
8197 */ | 8129 */ |
8198 static void | 8130 static void |
8199 f_getfsize(argvars, rettv) | 8131 f_getfsize(argvars, rettv) |
8200 typeval *argvars; | 8132 typval_T *argvars; |
8201 typeval *rettv; | 8133 typval_T *rettv; |
8202 { | 8134 { |
8203 char_u *fname; | 8135 char_u *fname; |
8204 struct stat st; | 8136 struct stat st; |
8205 | 8137 |
8206 fname = get_tv_string(&argvars[0]); | 8138 fname = get_tv_string(&argvars[0]); |
8221 /* | 8153 /* |
8222 * "getftime({fname})" function | 8154 * "getftime({fname})" function |
8223 */ | 8155 */ |
8224 static void | 8156 static void |
8225 f_getftime(argvars, rettv) | 8157 f_getftime(argvars, rettv) |
8226 typeval *argvars; | 8158 typval_T *argvars; |
8227 typeval *rettv; | 8159 typval_T *rettv; |
8228 { | 8160 { |
8229 char_u *fname; | 8161 char_u *fname; |
8230 struct stat st; | 8162 struct stat st; |
8231 | 8163 |
8232 fname = get_tv_string(&argvars[0]); | 8164 fname = get_tv_string(&argvars[0]); |
8240 /* | 8172 /* |
8241 * "getftype({fname})" function | 8173 * "getftype({fname})" function |
8242 */ | 8174 */ |
8243 static void | 8175 static void |
8244 f_getftype(argvars, rettv) | 8176 f_getftype(argvars, rettv) |
8245 typeval *argvars; | 8177 typval_T *argvars; |
8246 typeval *rettv; | 8178 typval_T *rettv; |
8247 { | 8179 { |
8248 char_u *fname; | 8180 char_u *fname; |
8249 struct stat st; | 8181 struct stat st; |
8250 char_u *type = NULL; | 8182 char_u *type = NULL; |
8251 char *t; | 8183 char *t; |
8320 /* | 8252 /* |
8321 * "getline(lnum)" function | 8253 * "getline(lnum)" function |
8322 */ | 8254 */ |
8323 static void | 8255 static void |
8324 f_getline(argvars, rettv) | 8256 f_getline(argvars, rettv) |
8325 typeval *argvars; | 8257 typval_T *argvars; |
8326 typeval *rettv; | 8258 typval_T *rettv; |
8327 { | 8259 { |
8328 linenr_T lnum; | 8260 linenr_T lnum; |
8329 linenr_T end; | 8261 linenr_T end; |
8330 char_u *p; | 8262 char_u *p; |
8331 listvar *l; | 8263 list_T *l; |
8332 listitem *li; | 8264 listitem_T *li; |
8333 | 8265 |
8334 lnum = get_tv_lnum(argvars); | 8266 lnum = get_tv_lnum(argvars); |
8335 | 8267 |
8336 if (argvars[1].v_type == VAR_UNKNOWN) | 8268 if (argvars[1].v_type == VAR_UNKNOWN) |
8337 { | 8269 { |
8380 /* | 8312 /* |
8381 * "getreg()" function | 8313 * "getreg()" function |
8382 */ | 8314 */ |
8383 static void | 8315 static void |
8384 f_getreg(argvars, rettv) | 8316 f_getreg(argvars, rettv) |
8385 typeval *argvars; | 8317 typval_T *argvars; |
8386 typeval *rettv; | 8318 typval_T *rettv; |
8387 { | 8319 { |
8388 char_u *strregname; | 8320 char_u *strregname; |
8389 int regname; | 8321 int regname; |
8390 | 8322 |
8391 if (argvars[0].v_type != VAR_UNKNOWN) | 8323 if (argvars[0].v_type != VAR_UNKNOWN) |
8403 /* | 8335 /* |
8404 * "getregtype()" function | 8336 * "getregtype()" function |
8405 */ | 8337 */ |
8406 static void | 8338 static void |
8407 f_getregtype(argvars, rettv) | 8339 f_getregtype(argvars, rettv) |
8408 typeval *argvars; | 8340 typval_T *argvars; |
8409 typeval *rettv; | 8341 typval_T *rettv; |
8410 { | 8342 { |
8411 char_u *strregname; | 8343 char_u *strregname; |
8412 int regname; | 8344 int regname; |
8413 char_u buf[NUMBUFLEN + 2]; | 8345 char_u buf[NUMBUFLEN + 2]; |
8414 long reglen = 0; | 8346 long reglen = 0; |
8444 * "getwinposx()" function | 8376 * "getwinposx()" function |
8445 */ | 8377 */ |
8446 /*ARGSUSED*/ | 8378 /*ARGSUSED*/ |
8447 static void | 8379 static void |
8448 f_getwinposx(argvars, rettv) | 8380 f_getwinposx(argvars, rettv) |
8449 typeval *argvars; | 8381 typval_T *argvars; |
8450 typeval *rettv; | 8382 typval_T *rettv; |
8451 { | 8383 { |
8452 rettv->vval.v_number = -1; | 8384 rettv->vval.v_number = -1; |
8453 #ifdef FEAT_GUI | 8385 #ifdef FEAT_GUI |
8454 if (gui.in_use) | 8386 if (gui.in_use) |
8455 { | 8387 { |
8465 * "getwinposy()" function | 8397 * "getwinposy()" function |
8466 */ | 8398 */ |
8467 /*ARGSUSED*/ | 8399 /*ARGSUSED*/ |
8468 static void | 8400 static void |
8469 f_getwinposy(argvars, rettv) | 8401 f_getwinposy(argvars, rettv) |
8470 typeval *argvars; | 8402 typval_T *argvars; |
8471 typeval *rettv; | 8403 typval_T *rettv; |
8472 { | 8404 { |
8473 rettv->vval.v_number = -1; | 8405 rettv->vval.v_number = -1; |
8474 #ifdef FEAT_GUI | 8406 #ifdef FEAT_GUI |
8475 if (gui.in_use) | 8407 if (gui.in_use) |
8476 { | 8408 { |
8485 /* | 8417 /* |
8486 * "getwinvar()" function | 8418 * "getwinvar()" function |
8487 */ | 8419 */ |
8488 static void | 8420 static void |
8489 f_getwinvar(argvars, rettv) | 8421 f_getwinvar(argvars, rettv) |
8490 typeval *argvars; | 8422 typval_T *argvars; |
8491 typeval *rettv; | 8423 typval_T *rettv; |
8492 { | 8424 { |
8493 win_T *win, *oldcurwin; | 8425 win_T *win, *oldcurwin; |
8494 char_u *varname; | 8426 char_u *varname; |
8495 VAR v; | 8427 dictitem_T *v; |
8496 | 8428 |
8497 ++emsg_off; | 8429 ++emsg_off; |
8498 win = find_win_by_nr(&argvars[0]); | 8430 win = find_win_by_nr(&argvars[0]); |
8499 varname = get_tv_string(&argvars[1]); | 8431 varname = get_tv_string(&argvars[1]); |
8500 | 8432 |
8515 curwin = oldcurwin; | 8447 curwin = oldcurwin; |
8516 } | 8448 } |
8517 else | 8449 else |
8518 { | 8450 { |
8519 /* look up the variable */ | 8451 /* look up the variable */ |
8520 v = find_var_in_ht(&win->w_vars, varname); | 8452 v = find_var_in_ht(&win->w_vars.dv_hashtab, varname); |
8521 if (v != NULL) | 8453 if (v != NULL) |
8522 copy_tv(&v->tv, rettv); | 8454 copy_tv(&v->di_tv, rettv); |
8523 } | 8455 } |
8524 } | 8456 } |
8525 | 8457 |
8526 --emsg_off; | 8458 --emsg_off; |
8527 } | 8459 } |
8529 /* | 8461 /* |
8530 * "glob()" function | 8462 * "glob()" function |
8531 */ | 8463 */ |
8532 static void | 8464 static void |
8533 f_glob(argvars, rettv) | 8465 f_glob(argvars, rettv) |
8534 typeval *argvars; | 8466 typval_T *argvars; |
8535 typeval *rettv; | 8467 typval_T *rettv; |
8536 { | 8468 { |
8537 expand_T xpc; | 8469 expand_T xpc; |
8538 | 8470 |
8539 ExpandInit(&xpc); | 8471 ExpandInit(&xpc); |
8540 xpc.xp_context = EXPAND_FILES; | 8472 xpc.xp_context = EXPAND_FILES; |
8547 /* | 8479 /* |
8548 * "globpath()" function | 8480 * "globpath()" function |
8549 */ | 8481 */ |
8550 static void | 8482 static void |
8551 f_globpath(argvars, rettv) | 8483 f_globpath(argvars, rettv) |
8552 typeval *argvars; | 8484 typval_T *argvars; |
8553 typeval *rettv; | 8485 typval_T *rettv; |
8554 { | 8486 { |
8555 char_u buf1[NUMBUFLEN]; | 8487 char_u buf1[NUMBUFLEN]; |
8556 | 8488 |
8557 rettv->v_type = VAR_STRING; | 8489 rettv->v_type = VAR_STRING; |
8558 rettv->vval.v_string = globpath(get_tv_string(&argvars[0]), | 8490 rettv->vval.v_string = globpath(get_tv_string(&argvars[0]), |
8562 /* | 8494 /* |
8563 * "has()" function | 8495 * "has()" function |
8564 */ | 8496 */ |
8565 static void | 8497 static void |
8566 f_has(argvars, rettv) | 8498 f_has(argvars, rettv) |
8567 typeval *argvars; | 8499 typval_T *argvars; |
8568 typeval *rettv; | 8500 typval_T *rettv; |
8569 { | 8501 { |
8570 int i; | 8502 int i; |
8571 char_u *name; | 8503 char_u *name; |
8572 int n = FALSE; | 8504 int n = FALSE; |
8573 static char *(has_list[]) = | 8505 static char *(has_list[]) = |
8828 #endif | 8760 #endif |
8829 #ifdef FEAT_MULTI_LANG | 8761 #ifdef FEAT_MULTI_LANG |
8830 "multi_lang", | 8762 "multi_lang", |
8831 #endif | 8763 #endif |
8832 #ifdef FEAT_MZSCHEME | 8764 #ifdef FEAT_MZSCHEME |
8765 #ifndef DYNAMIC_MZSCHEME | |
8833 "mzscheme", | 8766 "mzscheme", |
8767 #endif | |
8834 #endif | 8768 #endif |
8835 #ifdef FEAT_OLE | 8769 #ifdef FEAT_OLE |
8836 "ole", | 8770 "ole", |
8837 #endif | 8771 #endif |
8838 #ifdef FEAT_OSFILETYPE | 8772 #ifdef FEAT_OSFILETYPE |
9009 n = tcl_enabled(FALSE); | 8943 n = tcl_enabled(FALSE); |
9010 #endif | 8944 #endif |
9011 #if defined(USE_ICONV) && defined(DYNAMIC_ICONV) | 8945 #if defined(USE_ICONV) && defined(DYNAMIC_ICONV) |
9012 else if (STRICMP(name, "iconv") == 0) | 8946 else if (STRICMP(name, "iconv") == 0) |
9013 n = iconv_enabled(FALSE); | 8947 n = iconv_enabled(FALSE); |
8948 #endif | |
8949 #ifdef DYNAMIC_MZSCHEME | |
8950 else if (STRICMP(name, "mzscheme") == 0) | |
8951 n = mzscheme_enabled(FALSE); | |
9014 #endif | 8952 #endif |
9015 #ifdef DYNAMIC_RUBY | 8953 #ifdef DYNAMIC_RUBY |
9016 else if (STRICMP(name, "ruby") == 0) | 8954 else if (STRICMP(name, "ruby") == 0) |
9017 n = ruby_enabled(FALSE); | 8955 n = ruby_enabled(FALSE); |
9018 #endif | 8956 #endif |
9056 /* | 8994 /* |
9057 * "has_key()" function | 8995 * "has_key()" function |
9058 */ | 8996 */ |
9059 static void | 8997 static void |
9060 f_has_key(argvars, rettv) | 8998 f_has_key(argvars, rettv) |
9061 typeval *argvars; | 8999 typval_T *argvars; |
9062 typeval *rettv; | 9000 typval_T *rettv; |
9063 { | 9001 { |
9064 rettv->vval.v_number = 0; | 9002 rettv->vval.v_number = 0; |
9065 if (argvars[0].v_type != VAR_DICT) | 9003 if (argvars[0].v_type != VAR_DICT) |
9066 { | 9004 { |
9067 EMSG(_(e_dictreq)); | 9005 EMSG(_(e_dictreq)); |
9077 /* | 9015 /* |
9078 * "hasmapto()" function | 9016 * "hasmapto()" function |
9079 */ | 9017 */ |
9080 static void | 9018 static void |
9081 f_hasmapto(argvars, rettv) | 9019 f_hasmapto(argvars, rettv) |
9082 typeval *argvars; | 9020 typval_T *argvars; |
9083 typeval *rettv; | 9021 typval_T *rettv; |
9084 { | 9022 { |
9085 char_u *name; | 9023 char_u *name; |
9086 char_u *mode; | 9024 char_u *mode; |
9087 char_u buf[NUMBUFLEN]; | 9025 char_u buf[NUMBUFLEN]; |
9088 | 9026 |
9102 * "histadd()" function | 9040 * "histadd()" function |
9103 */ | 9041 */ |
9104 /*ARGSUSED*/ | 9042 /*ARGSUSED*/ |
9105 static void | 9043 static void |
9106 f_histadd(argvars, rettv) | 9044 f_histadd(argvars, rettv) |
9107 typeval *argvars; | 9045 typval_T *argvars; |
9108 typeval *rettv; | 9046 typval_T *rettv; |
9109 { | 9047 { |
9110 #ifdef FEAT_CMDHIST | 9048 #ifdef FEAT_CMDHIST |
9111 int histype; | 9049 int histype; |
9112 char_u *str; | 9050 char_u *str; |
9113 char_u buf[NUMBUFLEN]; | 9051 char_u buf[NUMBUFLEN]; |
9135 * "histdel()" function | 9073 * "histdel()" function |
9136 */ | 9074 */ |
9137 /*ARGSUSED*/ | 9075 /*ARGSUSED*/ |
9138 static void | 9076 static void |
9139 f_histdel(argvars, rettv) | 9077 f_histdel(argvars, rettv) |
9140 typeval *argvars; | 9078 typval_T *argvars; |
9141 typeval *rettv; | 9079 typval_T *rettv; |
9142 { | 9080 { |
9143 #ifdef FEAT_CMDHIST | 9081 #ifdef FEAT_CMDHIST |
9144 int n; | 9082 int n; |
9145 char_u buf[NUMBUFLEN]; | 9083 char_u buf[NUMBUFLEN]; |
9146 | 9084 |
9165 * "histget()" function | 9103 * "histget()" function |
9166 */ | 9104 */ |
9167 /*ARGSUSED*/ | 9105 /*ARGSUSED*/ |
9168 static void | 9106 static void |
9169 f_histget(argvars, rettv) | 9107 f_histget(argvars, rettv) |
9170 typeval *argvars; | 9108 typval_T *argvars; |
9171 typeval *rettv; | 9109 typval_T *rettv; |
9172 { | 9110 { |
9173 #ifdef FEAT_CMDHIST | 9111 #ifdef FEAT_CMDHIST |
9174 int type; | 9112 int type; |
9175 int idx; | 9113 int idx; |
9176 | 9114 |
9190 * "histnr()" function | 9128 * "histnr()" function |
9191 */ | 9129 */ |
9192 /*ARGSUSED*/ | 9130 /*ARGSUSED*/ |
9193 static void | 9131 static void |
9194 f_histnr(argvars, rettv) | 9132 f_histnr(argvars, rettv) |
9195 typeval *argvars; | 9133 typval_T *argvars; |
9196 typeval *rettv; | 9134 typval_T *rettv; |
9197 { | 9135 { |
9198 int i; | 9136 int i; |
9199 | 9137 |
9200 #ifdef FEAT_CMDHIST | 9138 #ifdef FEAT_CMDHIST |
9201 i = get_histtype(get_tv_string(&argvars[0])); | 9139 i = get_histtype(get_tv_string(&argvars[0])); |
9210 /* | 9148 /* |
9211 * "highlightID(name)" function | 9149 * "highlightID(name)" function |
9212 */ | 9150 */ |
9213 static void | 9151 static void |
9214 f_hlID(argvars, rettv) | 9152 f_hlID(argvars, rettv) |
9215 typeval *argvars; | 9153 typval_T *argvars; |
9216 typeval *rettv; | 9154 typval_T *rettv; |
9217 { | 9155 { |
9218 rettv->vval.v_number = syn_name2id(get_tv_string(&argvars[0])); | 9156 rettv->vval.v_number = syn_name2id(get_tv_string(&argvars[0])); |
9219 } | 9157 } |
9220 | 9158 |
9221 /* | 9159 /* |
9222 * "highlight_exists()" function | 9160 * "highlight_exists()" function |
9223 */ | 9161 */ |
9224 static void | 9162 static void |
9225 f_hlexists(argvars, rettv) | 9163 f_hlexists(argvars, rettv) |
9226 typeval *argvars; | 9164 typval_T *argvars; |
9227 typeval *rettv; | 9165 typval_T *rettv; |
9228 { | 9166 { |
9229 rettv->vval.v_number = highlight_exists(get_tv_string(&argvars[0])); | 9167 rettv->vval.v_number = highlight_exists(get_tv_string(&argvars[0])); |
9230 } | 9168 } |
9231 | 9169 |
9232 /* | 9170 /* |
9233 * "hostname()" function | 9171 * "hostname()" function |
9234 */ | 9172 */ |
9235 /*ARGSUSED*/ | 9173 /*ARGSUSED*/ |
9236 static void | 9174 static void |
9237 f_hostname(argvars, rettv) | 9175 f_hostname(argvars, rettv) |
9238 typeval *argvars; | 9176 typval_T *argvars; |
9239 typeval *rettv; | 9177 typval_T *rettv; |
9240 { | 9178 { |
9241 char_u hostname[256]; | 9179 char_u hostname[256]; |
9242 | 9180 |
9243 mch_get_host_name(hostname, 256); | 9181 mch_get_host_name(hostname, 256); |
9244 rettv->v_type = VAR_STRING; | 9182 rettv->v_type = VAR_STRING; |
9249 * iconv() function | 9187 * iconv() function |
9250 */ | 9188 */ |
9251 /*ARGSUSED*/ | 9189 /*ARGSUSED*/ |
9252 static void | 9190 static void |
9253 f_iconv(argvars, rettv) | 9191 f_iconv(argvars, rettv) |
9254 typeval *argvars; | 9192 typval_T *argvars; |
9255 typeval *rettv; | 9193 typval_T *rettv; |
9256 { | 9194 { |
9257 #ifdef FEAT_MBYTE | 9195 #ifdef FEAT_MBYTE |
9258 char_u buf1[NUMBUFLEN]; | 9196 char_u buf1[NUMBUFLEN]; |
9259 char_u buf2[NUMBUFLEN]; | 9197 char_u buf2[NUMBUFLEN]; |
9260 char_u *from, *to, *str; | 9198 char_u *from, *to, *str; |
9286 /* | 9224 /* |
9287 * "indent()" function | 9225 * "indent()" function |
9288 */ | 9226 */ |
9289 static void | 9227 static void |
9290 f_indent(argvars, rettv) | 9228 f_indent(argvars, rettv) |
9291 typeval *argvars; | 9229 typval_T *argvars; |
9292 typeval *rettv; | 9230 typval_T *rettv; |
9293 { | 9231 { |
9294 linenr_T lnum; | 9232 linenr_T lnum; |
9295 | 9233 |
9296 lnum = get_tv_lnum(argvars); | 9234 lnum = get_tv_lnum(argvars); |
9297 if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count) | 9235 if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count) |
9303 /* | 9241 /* |
9304 * "index()" function | 9242 * "index()" function |
9305 */ | 9243 */ |
9306 static void | 9244 static void |
9307 f_index(argvars, rettv) | 9245 f_index(argvars, rettv) |
9308 typeval *argvars; | 9246 typval_T *argvars; |
9309 typeval *rettv; | 9247 typval_T *rettv; |
9310 { | 9248 { |
9311 listvar *l; | 9249 list_T *l; |
9312 listitem *item; | 9250 listitem_T *item; |
9313 long idx = 0; | 9251 long idx = 0; |
9314 long min_idx = 0; | 9252 long min_idx = 0; |
9315 int ic = FALSE; | 9253 int ic = FALSE; |
9316 | 9254 |
9317 rettv->vval.v_number = -1; | 9255 rettv->vval.v_number = -1; |
9345 * "input()" function | 9283 * "input()" function |
9346 * Also handles inputsecret() when inputsecret is set. | 9284 * Also handles inputsecret() when inputsecret is set. |
9347 */ | 9285 */ |
9348 static void | 9286 static void |
9349 f_input(argvars, rettv) | 9287 f_input(argvars, rettv) |
9350 typeval *argvars; | 9288 typval_T *argvars; |
9351 typeval *rettv; | 9289 typval_T *rettv; |
9352 { | 9290 { |
9353 char_u *prompt = get_tv_string(&argvars[0]); | 9291 char_u *prompt = get_tv_string(&argvars[0]); |
9354 char_u *p = NULL; | 9292 char_u *p = NULL; |
9355 int c; | 9293 int c; |
9356 char_u buf[NUMBUFLEN]; | 9294 char_u buf[NUMBUFLEN]; |
9405 /* | 9343 /* |
9406 * "inputdialog()" function | 9344 * "inputdialog()" function |
9407 */ | 9345 */ |
9408 static void | 9346 static void |
9409 f_inputdialog(argvars, rettv) | 9347 f_inputdialog(argvars, rettv) |
9410 typeval *argvars; | 9348 typval_T *argvars; |
9411 typeval *rettv; | 9349 typval_T *rettv; |
9412 { | 9350 { |
9413 #if defined(FEAT_GUI_TEXTDIALOG) | 9351 #if defined(FEAT_GUI_TEXTDIALOG) |
9414 /* Use a GUI dialog if the GUI is running and 'c' is not in 'guioptions' */ | 9352 /* Use a GUI dialog if the GUI is running and 'c' is not in 'guioptions' */ |
9415 if (gui.in_use && vim_strchr(p_go, GO_CONDIALOG) == NULL) | 9353 if (gui.in_use && vim_strchr(p_go, GO_CONDIALOG) == NULL) |
9416 { | 9354 { |
9450 * "inputrestore()" function | 9388 * "inputrestore()" function |
9451 */ | 9389 */ |
9452 /*ARGSUSED*/ | 9390 /*ARGSUSED*/ |
9453 static void | 9391 static void |
9454 f_inputrestore(argvars, rettv) | 9392 f_inputrestore(argvars, rettv) |
9455 typeval *argvars; | 9393 typval_T *argvars; |
9456 typeval *rettv; | 9394 typval_T *rettv; |
9457 { | 9395 { |
9458 if (ga_userinput.ga_len > 0) | 9396 if (ga_userinput.ga_len > 0) |
9459 { | 9397 { |
9460 --ga_userinput.ga_len; | 9398 --ga_userinput.ga_len; |
9461 restore_typeahead((tasave_T *)(ga_userinput.ga_data) | 9399 restore_typeahead((tasave_T *)(ga_userinput.ga_data) |
9473 * "inputsave()" function | 9411 * "inputsave()" function |
9474 */ | 9412 */ |
9475 /*ARGSUSED*/ | 9413 /*ARGSUSED*/ |
9476 static void | 9414 static void |
9477 f_inputsave(argvars, rettv) | 9415 f_inputsave(argvars, rettv) |
9478 typeval *argvars; | 9416 typval_T *argvars; |
9479 typeval *rettv; | 9417 typval_T *rettv; |
9480 { | 9418 { |
9481 /* Add an entry to the stack of typehead storage. */ | 9419 /* Add an entry to the stack of typehead storage. */ |
9482 if (ga_grow(&ga_userinput, 1) == OK) | 9420 if (ga_grow(&ga_userinput, 1) == OK) |
9483 { | 9421 { |
9484 save_typeahead((tasave_T *)(ga_userinput.ga_data) | 9422 save_typeahead((tasave_T *)(ga_userinput.ga_data) |
9493 /* | 9431 /* |
9494 * "inputsecret()" function | 9432 * "inputsecret()" function |
9495 */ | 9433 */ |
9496 static void | 9434 static void |
9497 f_inputsecret(argvars, rettv) | 9435 f_inputsecret(argvars, rettv) |
9498 typeval *argvars; | 9436 typval_T *argvars; |
9499 typeval *rettv; | 9437 typval_T *rettv; |
9500 { | 9438 { |
9501 ++cmdline_star; | 9439 ++cmdline_star; |
9502 ++inputsecret_flag; | 9440 ++inputsecret_flag; |
9503 f_input(argvars, rettv); | 9441 f_input(argvars, rettv); |
9504 --cmdline_star; | 9442 --cmdline_star; |
9508 /* | 9446 /* |
9509 * "insert()" function | 9447 * "insert()" function |
9510 */ | 9448 */ |
9511 static void | 9449 static void |
9512 f_insert(argvars, rettv) | 9450 f_insert(argvars, rettv) |
9513 typeval *argvars; | 9451 typval_T *argvars; |
9514 typeval *rettv; | 9452 typval_T *rettv; |
9515 { | 9453 { |
9516 long before = 0; | 9454 long before = 0; |
9517 long n; | 9455 long n; |
9518 listitem *item; | 9456 listitem_T *item; |
9519 listvar *l; | 9457 list_T *l; |
9520 | 9458 |
9521 if (argvars[0].v_type != VAR_LIST) | 9459 if (argvars[0].v_type != VAR_LIST) |
9522 EMSG2(_(e_listarg), "insert()"); | 9460 EMSG2(_(e_listarg), "insert()"); |
9523 else if ((l = argvars[0].vval.v_list) != NULL) | 9461 else if ((l = argvars[0].vval.v_list) != NULL) |
9524 { | 9462 { |
9541 /* | 9479 /* |
9542 * "isdirectory()" function | 9480 * "isdirectory()" function |
9543 */ | 9481 */ |
9544 static void | 9482 static void |
9545 f_isdirectory(argvars, rettv) | 9483 f_isdirectory(argvars, rettv) |
9546 typeval *argvars; | 9484 typval_T *argvars; |
9547 typeval *rettv; | 9485 typval_T *rettv; |
9548 { | 9486 { |
9549 rettv->vval.v_number = mch_isdir(get_tv_string(&argvars[0])); | 9487 rettv->vval.v_number = mch_isdir(get_tv_string(&argvars[0])); |
9550 } | 9488 } |
9551 | 9489 |
9552 static void dict_list __ARGS((typeval *argvars, typeval *rettv, int what)); | 9490 static void dict_list __ARGS((typval_T *argvars, typval_T *rettv, int what)); |
9553 | 9491 |
9554 /* | 9492 /* |
9555 * Turn a dict into a list: | 9493 * Turn a dict into a list: |
9556 * "what" == 0: list of keys | 9494 * "what" == 0: list of keys |
9557 * "what" == 1: list of values | 9495 * "what" == 1: list of values |
9558 * "what" == 2: list of items | 9496 * "what" == 2: list of items |
9559 */ | 9497 */ |
9560 static void | 9498 static void |
9561 dict_list(argvars, rettv, what) | 9499 dict_list(argvars, rettv, what) |
9562 typeval *argvars; | 9500 typval_T *argvars; |
9563 typeval *rettv; | 9501 typval_T *rettv; |
9564 int what; | 9502 int what; |
9565 { | 9503 { |
9566 listvar *l; | 9504 list_T *l; |
9567 listvar *l2; | 9505 list_T *l2; |
9568 dictitem *di; | 9506 dictitem_T *di; |
9569 hashitem *hi; | 9507 hashitem_T *hi; |
9570 listitem *li; | 9508 listitem_T *li; |
9571 listitem *li2; | 9509 listitem_T *li2; |
9572 dictvar *d; | 9510 dict_T *d; |
9573 int todo; | 9511 int todo; |
9574 | 9512 |
9575 rettv->vval.v_number = 0; | 9513 rettv->vval.v_number = 0; |
9576 if (argvars[0].v_type != VAR_DICT) | 9514 if (argvars[0].v_type != VAR_DICT) |
9577 { | 9515 { |
9586 return; | 9524 return; |
9587 rettv->v_type = VAR_LIST; | 9525 rettv->v_type = VAR_LIST; |
9588 rettv->vval.v_list = l; | 9526 rettv->vval.v_list = l; |
9589 ++l->lv_refcount; | 9527 ++l->lv_refcount; |
9590 | 9528 |
9591 todo = d->dv_hashtable.ht_used; | 9529 todo = d->dv_hashtab.ht_used; |
9592 for (hi = d->dv_hashtable.ht_array; todo > 0; ++hi) | 9530 for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) |
9593 { | 9531 { |
9594 if (!HASHITEM_EMPTY(hi)) | 9532 if (!HASHITEM_EMPTY(hi)) |
9595 { | 9533 { |
9596 --todo; | 9534 --todo; |
9597 di = HI2DI(hi); | 9535 di = HI2DI(hi); |
9642 /* | 9580 /* |
9643 * "items(dict)" function | 9581 * "items(dict)" function |
9644 */ | 9582 */ |
9645 static void | 9583 static void |
9646 f_items(argvars, rettv) | 9584 f_items(argvars, rettv) |
9647 typeval *argvars; | 9585 typval_T *argvars; |
9648 typeval *rettv; | 9586 typval_T *rettv; |
9649 { | 9587 { |
9650 dict_list(argvars, rettv, 2); | 9588 dict_list(argvars, rettv, 2); |
9651 } | 9589 } |
9652 | 9590 |
9653 /* | 9591 /* |
9654 * "join()" function | 9592 * "join()" function |
9655 */ | 9593 */ |
9656 static void | 9594 static void |
9657 f_join(argvars, rettv) | 9595 f_join(argvars, rettv) |
9658 typeval *argvars; | 9596 typval_T *argvars; |
9659 typeval *rettv; | 9597 typval_T *rettv; |
9660 { | 9598 { |
9661 garray_T ga; | 9599 garray_T ga; |
9662 char_u *sep; | 9600 char_u *sep; |
9663 | 9601 |
9664 rettv->vval.v_number = 0; | 9602 rettv->vval.v_number = 0; |
9685 /* | 9623 /* |
9686 * "keys()" function | 9624 * "keys()" function |
9687 */ | 9625 */ |
9688 static void | 9626 static void |
9689 f_keys(argvars, rettv) | 9627 f_keys(argvars, rettv) |
9690 typeval *argvars; | 9628 typval_T *argvars; |
9691 typeval *rettv; | 9629 typval_T *rettv; |
9692 { | 9630 { |
9693 dict_list(argvars, rettv, 0); | 9631 dict_list(argvars, rettv, 0); |
9694 } | 9632 } |
9695 | 9633 |
9696 /* | 9634 /* |
9697 * "last_buffer_nr()" function. | 9635 * "last_buffer_nr()" function. |
9698 */ | 9636 */ |
9699 /*ARGSUSED*/ | 9637 /*ARGSUSED*/ |
9700 static void | 9638 static void |
9701 f_last_buffer_nr(argvars, rettv) | 9639 f_last_buffer_nr(argvars, rettv) |
9702 typeval *argvars; | 9640 typval_T *argvars; |
9703 typeval *rettv; | 9641 typval_T *rettv; |
9704 { | 9642 { |
9705 int n = 0; | 9643 int n = 0; |
9706 buf_T *buf; | 9644 buf_T *buf; |
9707 | 9645 |
9708 for (buf = firstbuf; buf != NULL; buf = buf->b_next) | 9646 for (buf = firstbuf; buf != NULL; buf = buf->b_next) |
9715 /* | 9653 /* |
9716 * "len()" function | 9654 * "len()" function |
9717 */ | 9655 */ |
9718 static void | 9656 static void |
9719 f_len(argvars, rettv) | 9657 f_len(argvars, rettv) |
9720 typeval *argvars; | 9658 typval_T *argvars; |
9721 typeval *rettv; | 9659 typval_T *rettv; |
9722 { | 9660 { |
9723 switch (argvars[0].v_type) | 9661 switch (argvars[0].v_type) |
9724 { | 9662 { |
9725 case VAR_STRING: | 9663 case VAR_STRING: |
9726 case VAR_NUMBER: | 9664 case VAR_NUMBER: |
9737 EMSG(_("E701: Invalid type for len()")); | 9675 EMSG(_("E701: Invalid type for len()")); |
9738 break; | 9676 break; |
9739 } | 9677 } |
9740 } | 9678 } |
9741 | 9679 |
9742 static void libcall_common __ARGS((typeval *argvars, typeval *rettv, int type)); | 9680 static void libcall_common __ARGS((typval_T *argvars, typval_T *rettv, int type)); |
9743 | 9681 |
9744 static void | 9682 static void |
9745 libcall_common(argvars, rettv, type) | 9683 libcall_common(argvars, rettv, type) |
9746 typeval *argvars; | 9684 typval_T *argvars; |
9747 typeval *rettv; | 9685 typval_T *rettv; |
9748 int type; | 9686 int type; |
9749 { | 9687 { |
9750 #ifdef FEAT_LIBCALL | 9688 #ifdef FEAT_LIBCALL |
9751 char_u *string_in; | 9689 char_u *string_in; |
9752 char_u **string_result; | 9690 char_u **string_result; |
9789 /* | 9727 /* |
9790 * "libcall()" function | 9728 * "libcall()" function |
9791 */ | 9729 */ |
9792 static void | 9730 static void |
9793 f_libcall(argvars, rettv) | 9731 f_libcall(argvars, rettv) |
9794 typeval *argvars; | 9732 typval_T *argvars; |
9795 typeval *rettv; | 9733 typval_T *rettv; |
9796 { | 9734 { |
9797 libcall_common(argvars, rettv, VAR_STRING); | 9735 libcall_common(argvars, rettv, VAR_STRING); |
9798 } | 9736 } |
9799 | 9737 |
9800 /* | 9738 /* |
9801 * "libcallnr()" function | 9739 * "libcallnr()" function |
9802 */ | 9740 */ |
9803 static void | 9741 static void |
9804 f_libcallnr(argvars, rettv) | 9742 f_libcallnr(argvars, rettv) |
9805 typeval *argvars; | 9743 typval_T *argvars; |
9806 typeval *rettv; | 9744 typval_T *rettv; |
9807 { | 9745 { |
9808 libcall_common(argvars, rettv, VAR_NUMBER); | 9746 libcall_common(argvars, rettv, VAR_NUMBER); |
9809 } | 9747 } |
9810 | 9748 |
9811 /* | 9749 /* |
9812 * "line(string)" function | 9750 * "line(string)" function |
9813 */ | 9751 */ |
9814 static void | 9752 static void |
9815 f_line(argvars, rettv) | 9753 f_line(argvars, rettv) |
9816 typeval *argvars; | 9754 typval_T *argvars; |
9817 typeval *rettv; | 9755 typval_T *rettv; |
9818 { | 9756 { |
9819 linenr_T lnum = 0; | 9757 linenr_T lnum = 0; |
9820 pos_T *fp; | 9758 pos_T *fp; |
9821 | 9759 |
9822 fp = var2fpos(&argvars[0], TRUE); | 9760 fp = var2fpos(&argvars[0], TRUE); |
9829 * "line2byte(lnum)" function | 9767 * "line2byte(lnum)" function |
9830 */ | 9768 */ |
9831 /*ARGSUSED*/ | 9769 /*ARGSUSED*/ |
9832 static void | 9770 static void |
9833 f_line2byte(argvars, rettv) | 9771 f_line2byte(argvars, rettv) |
9834 typeval *argvars; | 9772 typval_T *argvars; |
9835 typeval *rettv; | 9773 typval_T *rettv; |
9836 { | 9774 { |
9837 #ifndef FEAT_BYTEOFF | 9775 #ifndef FEAT_BYTEOFF |
9838 rettv->vval.v_number = -1; | 9776 rettv->vval.v_number = -1; |
9839 #else | 9777 #else |
9840 linenr_T lnum; | 9778 linenr_T lnum; |
9852 /* | 9790 /* |
9853 * "lispindent(lnum)" function | 9791 * "lispindent(lnum)" function |
9854 */ | 9792 */ |
9855 static void | 9793 static void |
9856 f_lispindent(argvars, rettv) | 9794 f_lispindent(argvars, rettv) |
9857 typeval *argvars; | 9795 typval_T *argvars; |
9858 typeval *rettv; | 9796 typval_T *rettv; |
9859 { | 9797 { |
9860 #ifdef FEAT_LISP | 9798 #ifdef FEAT_LISP |
9861 pos_T pos; | 9799 pos_T pos; |
9862 linenr_T lnum; | 9800 linenr_T lnum; |
9863 | 9801 |
9878 * "localtime()" function | 9816 * "localtime()" function |
9879 */ | 9817 */ |
9880 /*ARGSUSED*/ | 9818 /*ARGSUSED*/ |
9881 static void | 9819 static void |
9882 f_localtime(argvars, rettv) | 9820 f_localtime(argvars, rettv) |
9883 typeval *argvars; | 9821 typval_T *argvars; |
9884 typeval *rettv; | 9822 typval_T *rettv; |
9885 { | 9823 { |
9886 rettv->vval.v_number = (varnumber_T)time(NULL); | 9824 rettv->vval.v_number = (varnumber_T)time(NULL); |
9887 } | 9825 } |
9888 | 9826 |
9889 static void get_maparg __ARGS((typeval *argvars, typeval *rettv, int exact)); | 9827 static void get_maparg __ARGS((typval_T *argvars, typval_T *rettv, int exact)); |
9890 | 9828 |
9891 static void | 9829 static void |
9892 get_maparg(argvars, rettv, exact) | 9830 get_maparg(argvars, rettv, exact) |
9893 typeval *argvars; | 9831 typval_T *argvars; |
9894 typeval *rettv; | 9832 typval_T *rettv; |
9895 int exact; | 9833 int exact; |
9896 { | 9834 { |
9897 char_u *keys; | 9835 char_u *keys; |
9898 char_u *which; | 9836 char_u *which; |
9899 char_u buf[NUMBUFLEN]; | 9837 char_u buf[NUMBUFLEN]; |
9936 /* | 9874 /* |
9937 * "map()" function | 9875 * "map()" function |
9938 */ | 9876 */ |
9939 static void | 9877 static void |
9940 f_map(argvars, rettv) | 9878 f_map(argvars, rettv) |
9941 typeval *argvars; | 9879 typval_T *argvars; |
9942 typeval *rettv; | 9880 typval_T *rettv; |
9943 { | 9881 { |
9944 filter_map(argvars, rettv, TRUE); | 9882 filter_map(argvars, rettv, TRUE); |
9945 } | 9883 } |
9946 | 9884 |
9947 /* | 9885 /* |
9948 * "maparg()" function | 9886 * "maparg()" function |
9949 */ | 9887 */ |
9950 static void | 9888 static void |
9951 f_maparg(argvars, rettv) | 9889 f_maparg(argvars, rettv) |
9952 typeval *argvars; | 9890 typval_T *argvars; |
9953 typeval *rettv; | 9891 typval_T *rettv; |
9954 { | 9892 { |
9955 get_maparg(argvars, rettv, TRUE); | 9893 get_maparg(argvars, rettv, TRUE); |
9956 } | 9894 } |
9957 | 9895 |
9958 /* | 9896 /* |
9959 * "mapcheck()" function | 9897 * "mapcheck()" function |
9960 */ | 9898 */ |
9961 static void | 9899 static void |
9962 f_mapcheck(argvars, rettv) | 9900 f_mapcheck(argvars, rettv) |
9963 typeval *argvars; | 9901 typval_T *argvars; |
9964 typeval *rettv; | 9902 typval_T *rettv; |
9965 { | 9903 { |
9966 get_maparg(argvars, rettv, FALSE); | 9904 get_maparg(argvars, rettv, FALSE); |
9967 } | 9905 } |
9968 | 9906 |
9969 static void find_some_match __ARGS((typeval *argvars, typeval *rettv, int start)); | 9907 static void find_some_match __ARGS((typval_T *argvars, typval_T *rettv, int start)); |
9970 | 9908 |
9971 static void | 9909 static void |
9972 find_some_match(argvars, rettv, type) | 9910 find_some_match(argvars, rettv, type) |
9973 typeval *argvars; | 9911 typval_T *argvars; |
9974 typeval *rettv; | 9912 typval_T *rettv; |
9975 int type; | 9913 int type; |
9976 { | 9914 { |
9977 char_u *str = NULL; | 9915 char_u *str = NULL; |
9978 char_u *expr = NULL; | 9916 char_u *expr = NULL; |
9979 char_u *pat; | 9917 char_u *pat; |
9982 char_u strbuf[NUMBUFLEN]; | 9920 char_u strbuf[NUMBUFLEN]; |
9983 char_u *save_cpo; | 9921 char_u *save_cpo; |
9984 long start = 0; | 9922 long start = 0; |
9985 long nth = 1; | 9923 long nth = 1; |
9986 int match; | 9924 int match; |
9987 listvar *l = NULL; | 9925 list_T *l = NULL; |
9988 listitem *li = NULL; | 9926 listitem_T *li = NULL; |
9989 long idx = 0; | 9927 long idx = 0; |
9990 char_u *tofree; | 9928 char_u *tofree; |
9991 | 9929 |
9992 /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ | 9930 /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ |
9993 save_cpo = p_cpo; | 9931 save_cpo = p_cpo; |
10020 li = list_find(l, start); | 9958 li = list_find(l, start); |
10021 if (li == NULL) | 9959 if (li == NULL) |
10022 goto theend; | 9960 goto theend; |
10023 if (start < 0) | 9961 if (start < 0) |
10024 { | 9962 { |
10025 listitem *ni; | 9963 listitem_T *ni; |
10026 | 9964 |
10027 /* Need to compute the index. */ | 9965 /* Need to compute the index. */ |
10028 for (ni = li; ni->li_prev != NULL; ni = ni->li_prev) | 9966 for (ni = li; ni->li_prev != NULL; ni = ni->li_prev) |
10029 ++idx; | 9967 ++idx; |
10030 } | 9968 } |
10119 /* | 10057 /* |
10120 * "match()" function | 10058 * "match()" function |
10121 */ | 10059 */ |
10122 static void | 10060 static void |
10123 f_match(argvars, rettv) | 10061 f_match(argvars, rettv) |
10124 typeval *argvars; | 10062 typval_T *argvars; |
10125 typeval *rettv; | 10063 typval_T *rettv; |
10126 { | 10064 { |
10127 find_some_match(argvars, rettv, 1); | 10065 find_some_match(argvars, rettv, 1); |
10128 } | 10066 } |
10129 | 10067 |
10130 /* | 10068 /* |
10131 * "matchend()" function | 10069 * "matchend()" function |
10132 */ | 10070 */ |
10133 static void | 10071 static void |
10134 f_matchend(argvars, rettv) | 10072 f_matchend(argvars, rettv) |
10135 typeval *argvars; | 10073 typval_T *argvars; |
10136 typeval *rettv; | 10074 typval_T *rettv; |
10137 { | 10075 { |
10138 find_some_match(argvars, rettv, 0); | 10076 find_some_match(argvars, rettv, 0); |
10139 } | 10077 } |
10140 | 10078 |
10141 /* | 10079 /* |
10142 * "matchstr()" function | 10080 * "matchstr()" function |
10143 */ | 10081 */ |
10144 static void | 10082 static void |
10145 f_matchstr(argvars, rettv) | 10083 f_matchstr(argvars, rettv) |
10146 typeval *argvars; | 10084 typval_T *argvars; |
10147 typeval *rettv; | 10085 typval_T *rettv; |
10148 { | 10086 { |
10149 find_some_match(argvars, rettv, 2); | 10087 find_some_match(argvars, rettv, 2); |
10150 } | 10088 } |
10151 | 10089 |
10152 static void max_min __ARGS((typeval *argvars, typeval *rettv, int domax)); | 10090 static void max_min __ARGS((typval_T *argvars, typval_T *rettv, int domax)); |
10153 | 10091 |
10154 static void | 10092 static void |
10155 max_min(argvars, rettv, domax) | 10093 max_min(argvars, rettv, domax) |
10156 typeval *argvars; | 10094 typval_T *argvars; |
10157 typeval *rettv; | 10095 typval_T *rettv; |
10158 int domax; | 10096 int domax; |
10159 { | 10097 { |
10160 long n = 0; | 10098 long n = 0; |
10161 long i; | 10099 long i; |
10162 | 10100 |
10163 if (argvars[0].v_type == VAR_LIST) | 10101 if (argvars[0].v_type == VAR_LIST) |
10164 { | 10102 { |
10165 listvar *l; | 10103 list_T *l; |
10166 listitem *li; | 10104 listitem_T *li; |
10167 | 10105 |
10168 l = argvars[0].vval.v_list; | 10106 l = argvars[0].vval.v_list; |
10169 if (l != NULL) | 10107 if (l != NULL) |
10170 { | 10108 { |
10171 li = l->lv_first; | 10109 li = l->lv_first; |
10184 } | 10122 } |
10185 } | 10123 } |
10186 } | 10124 } |
10187 else if (argvars[0].v_type == VAR_DICT) | 10125 else if (argvars[0].v_type == VAR_DICT) |
10188 { | 10126 { |
10189 dictvar *d; | 10127 dict_T *d; |
10190 int first = TRUE; | 10128 int first = TRUE; |
10191 hashitem *hi; | 10129 hashitem_T *hi; |
10192 int todo; | 10130 int todo; |
10193 | 10131 |
10194 d = argvars[0].vval.v_dict; | 10132 d = argvars[0].vval.v_dict; |
10195 if (d != NULL) | 10133 if (d != NULL) |
10196 { | 10134 { |
10197 todo = d->dv_hashtable.ht_used; | 10135 todo = d->dv_hashtab.ht_used; |
10198 for (hi = d->dv_hashtable.ht_array; todo > 0; ++hi) | 10136 for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) |
10199 { | 10137 { |
10200 if (!HASHITEM_EMPTY(hi)) | 10138 if (!HASHITEM_EMPTY(hi)) |
10201 { | 10139 { |
10202 --todo; | 10140 --todo; |
10203 i = get_tv_number(&HI2DI(hi)->di_tv); | 10141 i = get_tv_number(&HI2DI(hi)->di_tv); |
10220 /* | 10158 /* |
10221 * "max()" function | 10159 * "max()" function |
10222 */ | 10160 */ |
10223 static void | 10161 static void |
10224 f_max(argvars, rettv) | 10162 f_max(argvars, rettv) |
10225 typeval *argvars; | 10163 typval_T *argvars; |
10226 typeval *rettv; | 10164 typval_T *rettv; |
10227 { | 10165 { |
10228 max_min(argvars, rettv, TRUE); | 10166 max_min(argvars, rettv, TRUE); |
10229 } | 10167 } |
10230 | 10168 |
10231 /* | 10169 /* |
10232 * "min()" function | 10170 * "min()" function |
10233 */ | 10171 */ |
10234 static void | 10172 static void |
10235 f_min(argvars, rettv) | 10173 f_min(argvars, rettv) |
10236 typeval *argvars; | 10174 typval_T *argvars; |
10237 typeval *rettv; | 10175 typval_T *rettv; |
10238 { | 10176 { |
10239 max_min(argvars, rettv, FALSE); | 10177 max_min(argvars, rettv, FALSE); |
10240 } | 10178 } |
10241 | 10179 |
10242 /* | 10180 /* |
10243 * "mode()" function | 10181 * "mode()" function |
10244 */ | 10182 */ |
10245 /*ARGSUSED*/ | 10183 /*ARGSUSED*/ |
10246 static void | 10184 static void |
10247 f_mode(argvars, rettv) | 10185 f_mode(argvars, rettv) |
10248 typeval *argvars; | 10186 typval_T *argvars; |
10249 typeval *rettv; | 10187 typval_T *rettv; |
10250 { | 10188 { |
10251 char_u buf[2]; | 10189 char_u buf[2]; |
10252 | 10190 |
10253 #ifdef FEAT_VISUAL | 10191 #ifdef FEAT_VISUAL |
10254 if (VIsual_active) | 10192 if (VIsual_active) |
10282 /* | 10220 /* |
10283 * "nextnonblank()" function | 10221 * "nextnonblank()" function |
10284 */ | 10222 */ |
10285 static void | 10223 static void |
10286 f_nextnonblank(argvars, rettv) | 10224 f_nextnonblank(argvars, rettv) |
10287 typeval *argvars; | 10225 typval_T *argvars; |
10288 typeval *rettv; | 10226 typval_T *rettv; |
10289 { | 10227 { |
10290 linenr_T lnum; | 10228 linenr_T lnum; |
10291 | 10229 |
10292 for (lnum = get_tv_lnum(argvars); ; ++lnum) | 10230 for (lnum = get_tv_lnum(argvars); ; ++lnum) |
10293 { | 10231 { |
10305 /* | 10243 /* |
10306 * "nr2char()" function | 10244 * "nr2char()" function |
10307 */ | 10245 */ |
10308 static void | 10246 static void |
10309 f_nr2char(argvars, rettv) | 10247 f_nr2char(argvars, rettv) |
10310 typeval *argvars; | 10248 typval_T *argvars; |
10311 typeval *rettv; | 10249 typval_T *rettv; |
10312 { | 10250 { |
10313 char_u buf[NUMBUFLEN]; | 10251 char_u buf[NUMBUFLEN]; |
10314 | 10252 |
10315 #ifdef FEAT_MBYTE | 10253 #ifdef FEAT_MBYTE |
10316 if (has_mbyte) | 10254 if (has_mbyte) |
10328 /* | 10266 /* |
10329 * "prevnonblank()" function | 10267 * "prevnonblank()" function |
10330 */ | 10268 */ |
10331 static void | 10269 static void |
10332 f_prevnonblank(argvars, rettv) | 10270 f_prevnonblank(argvars, rettv) |
10333 typeval *argvars; | 10271 typval_T *argvars; |
10334 typeval *rettv; | 10272 typval_T *rettv; |
10335 { | 10273 { |
10336 linenr_T lnum; | 10274 linenr_T lnum; |
10337 | 10275 |
10338 lnum = get_tv_lnum(argvars); | 10276 lnum = get_tv_lnum(argvars); |
10339 if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count) | 10277 if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count) |
10347 /* | 10285 /* |
10348 * "range()" function | 10286 * "range()" function |
10349 */ | 10287 */ |
10350 static void | 10288 static void |
10351 f_range(argvars, rettv) | 10289 f_range(argvars, rettv) |
10352 typeval *argvars; | 10290 typval_T *argvars; |
10353 typeval *rettv; | 10291 typval_T *rettv; |
10354 { | 10292 { |
10355 long start; | 10293 long start; |
10356 long end; | 10294 long end; |
10357 long stride = 1; | 10295 long stride = 1; |
10358 long i; | 10296 long i; |
10359 listvar *l; | 10297 list_T *l; |
10360 listitem *li; | 10298 listitem_T *li; |
10361 | 10299 |
10362 start = get_tv_number(&argvars[0]); | 10300 start = get_tv_number(&argvars[0]); |
10363 if (argvars[1].v_type == VAR_UNKNOWN) | 10301 if (argvars[1].v_type == VAR_UNKNOWN) |
10364 { | 10302 { |
10365 end = start - 1; | 10303 end = start - 1; |
10430 return OK; | 10368 return OK; |
10431 } | 10369 } |
10432 #endif | 10370 #endif |
10433 | 10371 |
10434 #ifdef FEAT_CLIENTSERVER | 10372 #ifdef FEAT_CLIENTSERVER |
10435 static void remote_common __ARGS((typeval *argvars, typeval *rettv, int expr)); | 10373 static void remote_common __ARGS((typval_T *argvars, typval_T *rettv, int expr)); |
10436 | 10374 |
10437 static void | 10375 static void |
10438 remote_common(argvars, rettv, expr) | 10376 remote_common(argvars, rettv, expr) |
10439 typeval *argvars; | 10377 typval_T *argvars; |
10440 typeval *rettv; | 10378 typval_T *rettv; |
10441 int expr; | 10379 int expr; |
10442 { | 10380 { |
10443 char_u *server_name; | 10381 char_u *server_name; |
10444 char_u *keys; | 10382 char_u *keys; |
10445 char_u *r = NULL; | 10383 char_u *r = NULL; |
10476 | 10414 |
10477 rettv->vval.v_string = r; | 10415 rettv->vval.v_string = r; |
10478 | 10416 |
10479 if (argvars[2].v_type != VAR_UNKNOWN) | 10417 if (argvars[2].v_type != VAR_UNKNOWN) |
10480 { | 10418 { |
10481 var v; | 10419 dictitem_T v; |
10482 char_u str[30]; | 10420 char_u str[30]; |
10483 | 10421 |
10484 sprintf((char *)str, "0x%x", (unsigned int)w); | 10422 sprintf((char *)str, "0x%x", (unsigned int)w); |
10485 v.tv.v_type = VAR_STRING; | 10423 v.di_tv.v_type = VAR_STRING; |
10486 v.tv.vval.v_string = vim_strsave(str); | 10424 v.di_tv.vval.v_string = vim_strsave(str); |
10487 set_var(get_tv_string(&argvars[2]), &v.tv, FALSE); | 10425 set_var(get_tv_string(&argvars[2]), &v.di_tv, FALSE); |
10488 vim_free(v.tv.vval.v_string); | 10426 vim_free(v.di_tv.vval.v_string); |
10489 } | 10427 } |
10490 } | 10428 } |
10491 #endif | 10429 #endif |
10492 | 10430 |
10493 /* | 10431 /* |
10494 * "remote_expr()" function | 10432 * "remote_expr()" function |
10495 */ | 10433 */ |
10496 /*ARGSUSED*/ | 10434 /*ARGSUSED*/ |
10497 static void | 10435 static void |
10498 f_remote_expr(argvars, rettv) | 10436 f_remote_expr(argvars, rettv) |
10499 typeval *argvars; | 10437 typval_T *argvars; |
10500 typeval *rettv; | 10438 typval_T *rettv; |
10501 { | 10439 { |
10502 rettv->v_type = VAR_STRING; | 10440 rettv->v_type = VAR_STRING; |
10503 rettv->vval.v_string = NULL; | 10441 rettv->vval.v_string = NULL; |
10504 #ifdef FEAT_CLIENTSERVER | 10442 #ifdef FEAT_CLIENTSERVER |
10505 remote_common(argvars, rettv, TRUE); | 10443 remote_common(argvars, rettv, TRUE); |
10510 * "remote_foreground()" function | 10448 * "remote_foreground()" function |
10511 */ | 10449 */ |
10512 /*ARGSUSED*/ | 10450 /*ARGSUSED*/ |
10513 static void | 10451 static void |
10514 f_remote_foreground(argvars, rettv) | 10452 f_remote_foreground(argvars, rettv) |
10515 typeval *argvars; | 10453 typval_T *argvars; |
10516 typeval *rettv; | 10454 typval_T *rettv; |
10517 { | 10455 { |
10518 rettv->vval.v_number = 0; | 10456 rettv->vval.v_number = 0; |
10519 #ifdef FEAT_CLIENTSERVER | 10457 #ifdef FEAT_CLIENTSERVER |
10520 # ifdef WIN32 | 10458 # ifdef WIN32 |
10521 /* On Win32 it's done in this application. */ | 10459 /* On Win32 it's done in this application. */ |
10532 } | 10470 } |
10533 | 10471 |
10534 /*ARGSUSED*/ | 10472 /*ARGSUSED*/ |
10535 static void | 10473 static void |
10536 f_remote_peek(argvars, rettv) | 10474 f_remote_peek(argvars, rettv) |
10537 typeval *argvars; | 10475 typval_T *argvars; |
10538 typeval *rettv; | 10476 typval_T *rettv; |
10539 { | 10477 { |
10540 #ifdef FEAT_CLIENTSERVER | 10478 #ifdef FEAT_CLIENTSERVER |
10541 var v; | 10479 dictitem_T v; |
10542 char_u *s = NULL; | 10480 char_u *s = NULL; |
10543 # ifdef WIN32 | 10481 # ifdef WIN32 |
10544 int n = 0; | 10482 int n = 0; |
10545 # endif | 10483 # endif |
10546 | 10484 |
10567 serverStrToWin(get_tv_string(&argvars[0])), &s); | 10505 serverStrToWin(get_tv_string(&argvars[0])), &s); |
10568 # endif | 10506 # endif |
10569 | 10507 |
10570 if (argvars[1].v_type != VAR_UNKNOWN && rettv->vval.v_number > 0) | 10508 if (argvars[1].v_type != VAR_UNKNOWN && rettv->vval.v_number > 0) |
10571 { | 10509 { |
10572 v.tv.v_type = VAR_STRING; | 10510 v.di_tv.v_type = VAR_STRING; |
10573 v.tv.vval.v_string = vim_strsave(s); | 10511 v.di_tv.vval.v_string = vim_strsave(s); |
10574 set_var(get_tv_string(&argvars[1]), &v.tv, FALSE); | 10512 set_var(get_tv_string(&argvars[1]), &v.di_tv, FALSE); |
10575 vim_free(v.tv.vval.v_string); | 10513 vim_free(v.di_tv.vval.v_string); |
10576 } | 10514 } |
10577 #else | 10515 #else |
10578 rettv->vval.v_number = -1; | 10516 rettv->vval.v_number = -1; |
10579 #endif | 10517 #endif |
10580 } | 10518 } |
10581 | 10519 |
10582 /*ARGSUSED*/ | 10520 /*ARGSUSED*/ |
10583 static void | 10521 static void |
10584 f_remote_read(argvars, rettv) | 10522 f_remote_read(argvars, rettv) |
10585 typeval *argvars; | 10523 typval_T *argvars; |
10586 typeval *rettv; | 10524 typval_T *rettv; |
10587 { | 10525 { |
10588 char_u *r = NULL; | 10526 char_u *r = NULL; |
10589 | 10527 |
10590 #ifdef FEAT_CLIENTSERVER | 10528 #ifdef FEAT_CLIENTSERVER |
10591 if (!check_restricted() && !check_secure()) | 10529 if (!check_restricted() && !check_secure()) |
10613 * "remote_send()" function | 10551 * "remote_send()" function |
10614 */ | 10552 */ |
10615 /*ARGSUSED*/ | 10553 /*ARGSUSED*/ |
10616 static void | 10554 static void |
10617 f_remote_send(argvars, rettv) | 10555 f_remote_send(argvars, rettv) |
10618 typeval *argvars; | 10556 typval_T *argvars; |
10619 typeval *rettv; | 10557 typval_T *rettv; |
10620 { | 10558 { |
10621 rettv->v_type = VAR_STRING; | 10559 rettv->v_type = VAR_STRING; |
10622 rettv->vval.v_string = NULL; | 10560 rettv->vval.v_string = NULL; |
10623 #ifdef FEAT_CLIENTSERVER | 10561 #ifdef FEAT_CLIENTSERVER |
10624 remote_common(argvars, rettv, FALSE); | 10562 remote_common(argvars, rettv, FALSE); |
10628 /* | 10566 /* |
10629 * "remove()" function | 10567 * "remove()" function |
10630 */ | 10568 */ |
10631 static void | 10569 static void |
10632 f_remove(argvars, rettv) | 10570 f_remove(argvars, rettv) |
10633 typeval *argvars; | 10571 typval_T *argvars; |
10634 typeval *rettv; | 10572 typval_T *rettv; |
10635 { | 10573 { |
10636 listvar *l; | 10574 list_T *l; |
10637 listitem *item, *item2; | 10575 listitem_T *item, *item2; |
10638 listitem *li; | 10576 listitem_T *li; |
10639 long idx; | 10577 long idx; |
10640 long end; | 10578 long end; |
10641 char_u *key; | 10579 char_u *key; |
10642 dictvar *d; | 10580 dict_T *d; |
10643 dictitem *di; | 10581 dictitem_T *di; |
10644 | 10582 |
10645 rettv->vval.v_number = 0; | 10583 rettv->vval.v_number = 0; |
10646 if (argvars[0].v_type == VAR_DICT) | 10584 if (argvars[0].v_type == VAR_DICT) |
10647 { | 10585 { |
10648 if (argvars[2].v_type != VAR_UNKNOWN) | 10586 if (argvars[2].v_type != VAR_UNKNOWN) |
10715 /* | 10653 /* |
10716 * "rename({from}, {to})" function | 10654 * "rename({from}, {to})" function |
10717 */ | 10655 */ |
10718 static void | 10656 static void |
10719 f_rename(argvars, rettv) | 10657 f_rename(argvars, rettv) |
10720 typeval *argvars; | 10658 typval_T *argvars; |
10721 typeval *rettv; | 10659 typval_T *rettv; |
10722 { | 10660 { |
10723 char_u buf[NUMBUFLEN]; | 10661 char_u buf[NUMBUFLEN]; |
10724 | 10662 |
10725 if (check_restricted() || check_secure()) | 10663 if (check_restricted() || check_secure()) |
10726 rettv->vval.v_number = -1; | 10664 rettv->vval.v_number = -1; |
10733 * "repeat()" function | 10671 * "repeat()" function |
10734 */ | 10672 */ |
10735 /*ARGSUSED*/ | 10673 /*ARGSUSED*/ |
10736 static void | 10674 static void |
10737 f_repeat(argvars, rettv) | 10675 f_repeat(argvars, rettv) |
10738 typeval *argvars; | 10676 typval_T *argvars; |
10739 typeval *rettv; | 10677 typval_T *rettv; |
10740 { | 10678 { |
10741 char_u *p; | 10679 char_u *p; |
10742 int n; | 10680 int n; |
10743 int slen; | 10681 int slen; |
10744 int len; | 10682 int len; |
10745 char_u *r; | 10683 char_u *r; |
10746 int i; | 10684 int i; |
10747 listvar *l; | 10685 list_T *l; |
10748 | 10686 |
10749 n = get_tv_number(&argvars[1]); | 10687 n = get_tv_number(&argvars[1]); |
10750 if (argvars[0].v_type == VAR_LIST) | 10688 if (argvars[0].v_type == VAR_LIST) |
10751 { | 10689 { |
10752 l = list_alloc(); | 10690 l = list_alloc(); |
10786 /* | 10724 /* |
10787 * "resolve()" function | 10725 * "resolve()" function |
10788 */ | 10726 */ |
10789 static void | 10727 static void |
10790 f_resolve(argvars, rettv) | 10728 f_resolve(argvars, rettv) |
10791 typeval *argvars; | 10729 typval_T *argvars; |
10792 typeval *rettv; | 10730 typval_T *rettv; |
10793 { | 10731 { |
10794 char_u *p; | 10732 char_u *p; |
10795 | 10733 |
10796 p = get_tv_string(&argvars[0]); | 10734 p = get_tv_string(&argvars[0]); |
10797 #ifdef FEAT_SHORTCUT | 10735 #ifdef FEAT_SHORTCUT |
10986 /* | 10924 /* |
10987 * "reverse({list})" function | 10925 * "reverse({list})" function |
10988 */ | 10926 */ |
10989 static void | 10927 static void |
10990 f_reverse(argvars, rettv) | 10928 f_reverse(argvars, rettv) |
10991 typeval *argvars; | 10929 typval_T *argvars; |
10992 typeval *rettv; | 10930 typval_T *rettv; |
10993 { | 10931 { |
10994 listvar *l; | 10932 list_T *l; |
10995 listitem *li, *ni; | 10933 listitem_T *li, *ni; |
10996 | 10934 |
10997 rettv->vval.v_number = 0; | 10935 rettv->vval.v_number = 0; |
10998 if (argvars[0].v_type != VAR_LIST) | 10936 if (argvars[0].v_type != VAR_LIST) |
10999 EMSG2(_(e_listarg), "reverse()"); | 10937 EMSG2(_(e_listarg), "reverse()"); |
11000 else if ((l = argvars[0].vval.v_list) != NULL) | 10938 else if ((l = argvars[0].vval.v_list) != NULL) |
11015 | 10953 |
11016 #define SP_NOMOVE 1 /* don't move cursor */ | 10954 #define SP_NOMOVE 1 /* don't move cursor */ |
11017 #define SP_REPEAT 2 /* repeat to find outer pair */ | 10955 #define SP_REPEAT 2 /* repeat to find outer pair */ |
11018 #define SP_RETCOUNT 4 /* return matchcount */ | 10956 #define SP_RETCOUNT 4 /* return matchcount */ |
11019 | 10957 |
11020 static int get_search_arg __ARGS((typeval *varp, int *flagsp)); | 10958 static int get_search_arg __ARGS((typval_T *varp, int *flagsp)); |
11021 | 10959 |
11022 /* | 10960 /* |
11023 * Get flags for a search function. | 10961 * Get flags for a search function. |
11024 * Possibly sets "p_ws". | 10962 * Possibly sets "p_ws". |
11025 * Returns BACKWARD, FORWARD or zero (for an error). | 10963 * Returns BACKWARD, FORWARD or zero (for an error). |
11026 */ | 10964 */ |
11027 static int | 10965 static int |
11028 get_search_arg(varp, flagsp) | 10966 get_search_arg(varp, flagsp) |
11029 typeval *varp; | 10967 typval_T *varp; |
11030 int *flagsp; | 10968 int *flagsp; |
11031 { | 10969 { |
11032 int dir = FORWARD; | 10970 int dir = FORWARD; |
11033 char_u *flags; | 10971 char_u *flags; |
11034 char_u nbuf[NUMBUFLEN]; | 10972 char_u nbuf[NUMBUFLEN]; |
11071 /* | 11009 /* |
11072 * "search()" function | 11010 * "search()" function |
11073 */ | 11011 */ |
11074 static void | 11012 static void |
11075 f_search(argvars, rettv) | 11013 f_search(argvars, rettv) |
11076 typeval *argvars; | 11014 typval_T *argvars; |
11077 typeval *rettv; | 11015 typval_T *rettv; |
11078 { | 11016 { |
11079 char_u *pat; | 11017 char_u *pat; |
11080 pos_T pos; | 11018 pos_T pos; |
11081 pos_T save_cursor; | 11019 pos_T save_cursor; |
11082 int save_p_ws = p_ws; | 11020 int save_p_ws = p_ws; |
11116 /* | 11054 /* |
11117 * "searchpair()" function | 11055 * "searchpair()" function |
11118 */ | 11056 */ |
11119 static void | 11057 static void |
11120 f_searchpair(argvars, rettv) | 11058 f_searchpair(argvars, rettv) |
11121 typeval *argvars; | 11059 typval_T *argvars; |
11122 typeval *rettv; | 11060 typval_T *rettv; |
11123 { | 11061 { |
11124 char_u *spat, *mpat, *epat; | 11062 char_u *spat, *mpat, *epat; |
11125 char_u *skip; | 11063 char_u *skip; |
11126 char_u *pat, *pat2, *pat3; | 11064 char_u *pat, *pat2, *pat3; |
11127 pos_T pos; | 11065 pos_T pos; |
11250 } | 11188 } |
11251 | 11189 |
11252 /*ARGSUSED*/ | 11190 /*ARGSUSED*/ |
11253 static void | 11191 static void |
11254 f_server2client(argvars, rettv) | 11192 f_server2client(argvars, rettv) |
11255 typeval *argvars; | 11193 typval_T *argvars; |
11256 typeval *rettv; | 11194 typval_T *rettv; |
11257 { | 11195 { |
11258 #ifdef FEAT_CLIENTSERVER | 11196 #ifdef FEAT_CLIENTSERVER |
11259 char_u buf[NUMBUFLEN]; | 11197 char_u buf[NUMBUFLEN]; |
11260 char_u *server = get_tv_string(&argvars[0]); | 11198 char_u *server = get_tv_string(&argvars[0]); |
11261 char_u *reply = get_tv_string_buf(&argvars[1], buf); | 11199 char_u *reply = get_tv_string_buf(&argvars[1], buf); |
11280 } | 11218 } |
11281 | 11219 |
11282 /*ARGSUSED*/ | 11220 /*ARGSUSED*/ |
11283 static void | 11221 static void |
11284 f_serverlist(argvars, rettv) | 11222 f_serverlist(argvars, rettv) |
11285 typeval *argvars; | 11223 typval_T *argvars; |
11286 typeval *rettv; | 11224 typval_T *rettv; |
11287 { | 11225 { |
11288 char_u *r = NULL; | 11226 char_u *r = NULL; |
11289 | 11227 |
11290 #ifdef FEAT_CLIENTSERVER | 11228 #ifdef FEAT_CLIENTSERVER |
11291 # ifdef WIN32 | 11229 # ifdef WIN32 |
11304 * "setbufvar()" function | 11242 * "setbufvar()" function |
11305 */ | 11243 */ |
11306 /*ARGSUSED*/ | 11244 /*ARGSUSED*/ |
11307 static void | 11245 static void |
11308 f_setbufvar(argvars, rettv) | 11246 f_setbufvar(argvars, rettv) |
11309 typeval *argvars; | 11247 typval_T *argvars; |
11310 typeval *rettv; | 11248 typval_T *rettv; |
11311 { | 11249 { |
11312 buf_T *buf; | 11250 buf_T *buf; |
11313 #ifdef FEAT_AUTOCMD | 11251 #ifdef FEAT_AUTOCMD |
11314 aco_save_T aco; | 11252 aco_save_T aco; |
11315 #else | 11253 #else |
11316 buf_T *save_curbuf; | 11254 buf_T *save_curbuf; |
11317 #endif | 11255 #endif |
11318 char_u *varname, *bufvarname; | 11256 char_u *varname, *bufvarname; |
11319 typeval *varp; | 11257 typval_T *varp; |
11320 char_u nbuf[NUMBUFLEN]; | 11258 char_u nbuf[NUMBUFLEN]; |
11321 | 11259 |
11322 if (check_restricted() || check_secure()) | 11260 if (check_restricted() || check_secure()) |
11323 return; | 11261 return; |
11324 ++emsg_off; | 11262 ++emsg_off; |
11367 /* | 11305 /* |
11368 * "setcmdpos()" function | 11306 * "setcmdpos()" function |
11369 */ | 11307 */ |
11370 static void | 11308 static void |
11371 f_setcmdpos(argvars, rettv) | 11309 f_setcmdpos(argvars, rettv) |
11372 typeval *argvars; | 11310 typval_T *argvars; |
11373 typeval *rettv; | 11311 typval_T *rettv; |
11374 { | 11312 { |
11375 rettv->vval.v_number = set_cmdline_pos( | 11313 rettv->vval.v_number = set_cmdline_pos( |
11376 (int)get_tv_number(&argvars[0]) - 1); | 11314 (int)get_tv_number(&argvars[0]) - 1); |
11377 } | 11315 } |
11378 | 11316 |
11379 /* | 11317 /* |
11380 * "setline()" function | 11318 * "setline()" function |
11381 */ | 11319 */ |
11382 static void | 11320 static void |
11383 f_setline(argvars, rettv) | 11321 f_setline(argvars, rettv) |
11384 typeval *argvars; | 11322 typval_T *argvars; |
11385 typeval *rettv; | 11323 typval_T *rettv; |
11386 { | 11324 { |
11387 linenr_T lnum; | 11325 linenr_T lnum; |
11388 char_u *line; | 11326 char_u *line; |
11389 | 11327 |
11390 lnum = get_tv_lnum(argvars); | 11328 lnum = get_tv_lnum(argvars); |
11405 /* | 11343 /* |
11406 * "setreg()" function | 11344 * "setreg()" function |
11407 */ | 11345 */ |
11408 static void | 11346 static void |
11409 f_setreg(argvars, rettv) | 11347 f_setreg(argvars, rettv) |
11410 typeval *argvars; | 11348 typval_T *argvars; |
11411 typeval *rettv; | 11349 typval_T *rettv; |
11412 { | 11350 { |
11413 int regname; | 11351 int regname; |
11414 char_u *strregname; | 11352 char_u *strregname; |
11415 char_u *stropt; | 11353 char_u *stropt; |
11416 int append; | 11354 int append; |
11468 * "setwinvar(expr)" function | 11406 * "setwinvar(expr)" function |
11469 */ | 11407 */ |
11470 /*ARGSUSED*/ | 11408 /*ARGSUSED*/ |
11471 static void | 11409 static void |
11472 f_setwinvar(argvars, rettv) | 11410 f_setwinvar(argvars, rettv) |
11473 typeval *argvars; | 11411 typval_T *argvars; |
11474 typeval *rettv; | 11412 typval_T *rettv; |
11475 { | 11413 { |
11476 win_T *win; | 11414 win_T *win; |
11477 #ifdef FEAT_WINDOWS | 11415 #ifdef FEAT_WINDOWS |
11478 win_T *save_curwin; | 11416 win_T *save_curwin; |
11479 #endif | 11417 #endif |
11480 char_u *varname, *winvarname; | 11418 char_u *varname, *winvarname; |
11481 typeval *varp; | 11419 typval_T *varp; |
11482 char_u nbuf[NUMBUFLEN]; | 11420 char_u nbuf[NUMBUFLEN]; |
11483 | 11421 |
11484 if (check_restricted() || check_secure()) | 11422 if (check_restricted() || check_secure()) |
11485 return; | 11423 return; |
11486 ++emsg_off; | 11424 ++emsg_off; |
11531 /* | 11469 /* |
11532 * "simplify()" function | 11470 * "simplify()" function |
11533 */ | 11471 */ |
11534 static void | 11472 static void |
11535 f_simplify(argvars, rettv) | 11473 f_simplify(argvars, rettv) |
11536 typeval *argvars; | 11474 typval_T *argvars; |
11537 typeval *rettv; | 11475 typval_T *rettv; |
11538 { | 11476 { |
11539 char_u *p; | 11477 char_u *p; |
11540 | 11478 |
11541 p = get_tv_string(&argvars[0]); | 11479 p = get_tv_string(&argvars[0]); |
11542 rettv->vval.v_string = vim_strsave(p); | 11480 rettv->vval.v_string = vim_strsave(p); |
11574 char_u *tofree1, *tofree2; | 11512 char_u *tofree1, *tofree2; |
11575 int res; | 11513 int res; |
11576 char_u numbuf1[NUMBUFLEN]; | 11514 char_u numbuf1[NUMBUFLEN]; |
11577 char_u numbuf2[NUMBUFLEN]; | 11515 char_u numbuf2[NUMBUFLEN]; |
11578 | 11516 |
11579 p1 = tv2string(&(*(listitem **)s1)->li_tv, &tofree1, numbuf1); | 11517 p1 = tv2string(&(*(listitem_T **)s1)->li_tv, &tofree1, numbuf1); |
11580 p2 = tv2string(&(*(listitem **)s2)->li_tv, &tofree2, numbuf2); | 11518 p2 = tv2string(&(*(listitem_T **)s2)->li_tv, &tofree2, numbuf2); |
11581 if (item_compare_ic) | 11519 if (item_compare_ic) |
11582 res = STRICMP(p1, p2); | 11520 res = STRICMP(p1, p2); |
11583 else | 11521 else |
11584 res = STRCMP(p1, p2); | 11522 res = STRCMP(p1, p2); |
11585 vim_free(tofree1); | 11523 vim_free(tofree1); |
11594 item_compare2(s1, s2) | 11532 item_compare2(s1, s2) |
11595 const void *s1; | 11533 const void *s1; |
11596 const void *s2; | 11534 const void *s2; |
11597 { | 11535 { |
11598 int res; | 11536 int res; |
11599 typeval rettv; | 11537 typval_T rettv; |
11600 typeval argv[2]; | 11538 typval_T argv[2]; |
11601 int dummy; | 11539 int dummy; |
11602 | 11540 |
11603 /* copy the values (is this really needed?) */ | 11541 /* copy the values (is this really needed?) */ |
11604 copy_tv(&(*(listitem **)s1)->li_tv, &argv[0]); | 11542 copy_tv(&(*(listitem_T **)s1)->li_tv, &argv[0]); |
11605 copy_tv(&(*(listitem **)s2)->li_tv, &argv[1]); | 11543 copy_tv(&(*(listitem_T **)s2)->li_tv, &argv[1]); |
11606 | 11544 |
11607 rettv.v_type = VAR_UNKNOWN; /* clear_tv() uses this */ | 11545 rettv.v_type = VAR_UNKNOWN; /* clear_tv() uses this */ |
11608 res = call_func(item_compare_func, STRLEN(item_compare_func), | 11546 res = call_func(item_compare_func, STRLEN(item_compare_func), |
11609 &rettv, 2, argv, 0L, 0L, &dummy, TRUE, NULL); | 11547 &rettv, 2, argv, 0L, 0L, &dummy, TRUE, NULL); |
11610 clear_tv(&argv[0]); | 11548 clear_tv(&argv[0]); |
11621 /* | 11559 /* |
11622 * "sort({list})" function | 11560 * "sort({list})" function |
11623 */ | 11561 */ |
11624 static void | 11562 static void |
11625 f_sort(argvars, rettv) | 11563 f_sort(argvars, rettv) |
11626 typeval *argvars; | 11564 typval_T *argvars; |
11627 typeval *rettv; | 11565 typval_T *rettv; |
11628 { | 11566 { |
11629 listvar *l; | 11567 list_T *l; |
11630 listitem *li; | 11568 listitem_T *li; |
11631 listitem **ptrs; | 11569 listitem_T **ptrs; |
11632 long len; | 11570 long len; |
11633 long i; | 11571 long i; |
11634 | 11572 |
11635 rettv->vval.v_number = 0; | 11573 rettv->vval.v_number = 0; |
11636 if (argvars[0].v_type != VAR_LIST) | 11574 if (argvars[0].v_type != VAR_LIST) |
11663 item_compare_func = get_tv_string(&argvars[1]); | 11601 item_compare_func = get_tv_string(&argvars[1]); |
11664 } | 11602 } |
11665 } | 11603 } |
11666 | 11604 |
11667 /* Make an array with each entry pointing to an item in the List. */ | 11605 /* Make an array with each entry pointing to an item in the List. */ |
11668 ptrs = (listitem **)alloc((int)(len * sizeof(listitem *))); | 11606 ptrs = (listitem_T **)alloc((int)(len * sizeof(listitem_T *))); |
11669 if (ptrs == NULL) | 11607 if (ptrs == NULL) |
11670 return; | 11608 return; |
11671 i = 0; | 11609 i = 0; |
11672 for (li = l->lv_first; li != NULL; li = li->li_next) | 11610 for (li = l->lv_first; li != NULL; li = li->li_next) |
11673 ptrs[i++] = li; | 11611 ptrs[i++] = li; |
11678 == ITEM_COMPARE_FAIL) | 11616 == ITEM_COMPARE_FAIL) |
11679 EMSG(_("E702: Sort compare function failed")); | 11617 EMSG(_("E702: Sort compare function failed")); |
11680 else | 11618 else |
11681 { | 11619 { |
11682 /* Sort the array with item pointers. */ | 11620 /* Sort the array with item pointers. */ |
11683 qsort((void *)ptrs, (size_t)len, sizeof(listitem *), | 11621 qsort((void *)ptrs, (size_t)len, sizeof(listitem_T *), |
11684 item_compare_func == NULL ? item_compare : item_compare2); | 11622 item_compare_func == NULL ? item_compare : item_compare2); |
11685 | 11623 |
11686 /* Clear the List and append the items in the sorted order. */ | 11624 /* Clear the List and append the items in the sorted order. */ |
11687 l->lv_first = l->lv_last = NULL; | 11625 l->lv_first = l->lv_last = NULL; |
11688 for (i = 0; i < len; ++i) | 11626 for (i = 0; i < len; ++i) |
11693 } | 11631 } |
11694 } | 11632 } |
11695 | 11633 |
11696 static void | 11634 static void |
11697 f_split(argvars, rettv) | 11635 f_split(argvars, rettv) |
11698 typeval *argvars; | 11636 typval_T *argvars; |
11699 typeval *rettv; | 11637 typval_T *rettv; |
11700 { | 11638 { |
11701 char_u *str; | 11639 char_u *str; |
11702 char_u *end; | 11640 char_u *end; |
11703 char_u *pat; | 11641 char_u *pat; |
11704 regmatch_T regmatch; | 11642 regmatch_T regmatch; |
11705 char_u patbuf[NUMBUFLEN]; | 11643 char_u patbuf[NUMBUFLEN]; |
11706 char_u *save_cpo; | 11644 char_u *save_cpo; |
11707 int match; | 11645 int match; |
11708 listitem *ni; | 11646 listitem_T *ni; |
11709 listvar *l; | 11647 list_T *l; |
11710 colnr_T col = 0; | 11648 colnr_T col = 0; |
11711 | 11649 |
11712 /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ | 11650 /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ |
11713 save_cpo = p_cpo; | 11651 save_cpo = p_cpo; |
11714 p_cpo = (char_u *)""; | 11652 p_cpo = (char_u *)""; |
11773 /* | 11711 /* |
11774 * "strftime({format}[, {time}])" function | 11712 * "strftime({format}[, {time}])" function |
11775 */ | 11713 */ |
11776 static void | 11714 static void |
11777 f_strftime(argvars, rettv) | 11715 f_strftime(argvars, rettv) |
11778 typeval *argvars; | 11716 typval_T *argvars; |
11779 typeval *rettv; | 11717 typval_T *rettv; |
11780 { | 11718 { |
11781 char_u result_buf[256]; | 11719 char_u result_buf[256]; |
11782 struct tm *curtime; | 11720 struct tm *curtime; |
11783 time_t seconds; | 11721 time_t seconds; |
11784 char_u *p; | 11722 char_u *p; |
11834 /* | 11772 /* |
11835 * "stridx()" function | 11773 * "stridx()" function |
11836 */ | 11774 */ |
11837 static void | 11775 static void |
11838 f_stridx(argvars, rettv) | 11776 f_stridx(argvars, rettv) |
11839 typeval *argvars; | 11777 typval_T *argvars; |
11840 typeval *rettv; | 11778 typval_T *rettv; |
11841 { | 11779 { |
11842 char_u buf[NUMBUFLEN]; | 11780 char_u buf[NUMBUFLEN]; |
11843 char_u *needle; | 11781 char_u *needle; |
11844 char_u *haystack; | 11782 char_u *haystack; |
11783 char_u *save_haystack; | |
11845 char_u *pos; | 11784 char_u *pos; |
11785 int start_idx; | |
11846 | 11786 |
11847 needle = get_tv_string(&argvars[1]); | 11787 needle = get_tv_string(&argvars[1]); |
11848 haystack = get_tv_string_buf(&argvars[0], buf); | 11788 save_haystack = haystack = get_tv_string_buf(&argvars[0], buf); |
11789 rettv->vval.v_number = -1; | |
11790 | |
11791 if (argvars[2].v_type != VAR_UNKNOWN) | |
11792 { | |
11793 start_idx = get_tv_number(&argvars[2]); | |
11794 if (start_idx < 0 || start_idx >= (int)STRLEN(haystack)) | |
11795 return; | |
11796 haystack += start_idx; | |
11797 } | |
11798 | |
11849 pos = (char_u *)strstr((char *)haystack, (char *)needle); | 11799 pos = (char_u *)strstr((char *)haystack, (char *)needle); |
11850 | 11800 if (pos != NULL) |
11851 if (pos == NULL) | 11801 rettv->vval.v_number = (varnumber_T)(pos - save_haystack); |
11852 rettv->vval.v_number = -1; | |
11853 else | |
11854 rettv->vval.v_number = (varnumber_T) (pos - haystack); | |
11855 } | 11802 } |
11856 | 11803 |
11857 /* | 11804 /* |
11858 * "string()" function | 11805 * "string()" function |
11859 */ | 11806 */ |
11860 static void | 11807 static void |
11861 f_string(argvars, rettv) | 11808 f_string(argvars, rettv) |
11862 typeval *argvars; | 11809 typval_T *argvars; |
11863 typeval *rettv; | 11810 typval_T *rettv; |
11864 { | 11811 { |
11865 char_u *tofree; | 11812 char_u *tofree; |
11866 char_u numbuf[NUMBUFLEN]; | 11813 char_u numbuf[NUMBUFLEN]; |
11867 | 11814 |
11868 rettv->v_type = VAR_STRING; | 11815 rettv->v_type = VAR_STRING; |
11874 /* | 11821 /* |
11875 * "strlen()" function | 11822 * "strlen()" function |
11876 */ | 11823 */ |
11877 static void | 11824 static void |
11878 f_strlen(argvars, rettv) | 11825 f_strlen(argvars, rettv) |
11879 typeval *argvars; | 11826 typval_T *argvars; |
11880 typeval *rettv; | 11827 typval_T *rettv; |
11881 { | 11828 { |
11882 rettv->vval.v_number = (varnumber_T)(STRLEN( | 11829 rettv->vval.v_number = (varnumber_T)(STRLEN( |
11883 get_tv_string(&argvars[0]))); | 11830 get_tv_string(&argvars[0]))); |
11884 } | 11831 } |
11885 | 11832 |
11886 /* | 11833 /* |
11887 * "strpart()" function | 11834 * "strpart()" function |
11888 */ | 11835 */ |
11889 static void | 11836 static void |
11890 f_strpart(argvars, rettv) | 11837 f_strpart(argvars, rettv) |
11891 typeval *argvars; | 11838 typval_T *argvars; |
11892 typeval *rettv; | 11839 typval_T *rettv; |
11893 { | 11840 { |
11894 char_u *p; | 11841 char_u *p; |
11895 int n; | 11842 int n; |
11896 int len; | 11843 int len; |
11897 int slen; | 11844 int slen; |
11928 /* | 11875 /* |
11929 * "strridx()" function | 11876 * "strridx()" function |
11930 */ | 11877 */ |
11931 static void | 11878 static void |
11932 f_strridx(argvars, rettv) | 11879 f_strridx(argvars, rettv) |
11933 typeval *argvars; | 11880 typval_T *argvars; |
11934 typeval *rettv; | 11881 typval_T *rettv; |
11935 { | 11882 { |
11936 char_u buf[NUMBUFLEN]; | 11883 char_u buf[NUMBUFLEN]; |
11937 char_u *needle; | 11884 char_u *needle; |
11938 char_u *haystack; | 11885 char_u *haystack; |
11939 char_u *rest; | 11886 char_u *rest; |
11962 /* | 11909 /* |
11963 * "strtrans()" function | 11910 * "strtrans()" function |
11964 */ | 11911 */ |
11965 static void | 11912 static void |
11966 f_strtrans(argvars, rettv) | 11913 f_strtrans(argvars, rettv) |
11967 typeval *argvars; | 11914 typval_T *argvars; |
11968 typeval *rettv; | 11915 typval_T *rettv; |
11969 { | 11916 { |
11970 rettv->v_type = VAR_STRING; | 11917 rettv->v_type = VAR_STRING; |
11971 rettv->vval.v_string = transstr(get_tv_string(&argvars[0])); | 11918 rettv->vval.v_string = transstr(get_tv_string(&argvars[0])); |
11972 } | 11919 } |
11973 | 11920 |
11974 /* | 11921 /* |
11975 * "submatch()" function | 11922 * "submatch()" function |
11976 */ | 11923 */ |
11977 static void | 11924 static void |
11978 f_submatch(argvars, rettv) | 11925 f_submatch(argvars, rettv) |
11979 typeval *argvars; | 11926 typval_T *argvars; |
11980 typeval *rettv; | 11927 typval_T *rettv; |
11981 { | 11928 { |
11982 rettv->v_type = VAR_STRING; | 11929 rettv->v_type = VAR_STRING; |
11983 rettv->vval.v_string = reg_submatch((int)get_tv_number(&argvars[0])); | 11930 rettv->vval.v_string = reg_submatch((int)get_tv_number(&argvars[0])); |
11984 } | 11931 } |
11985 | 11932 |
11986 /* | 11933 /* |
11987 * "substitute()" function | 11934 * "substitute()" function |
11988 */ | 11935 */ |
11989 static void | 11936 static void |
11990 f_substitute(argvars, rettv) | 11937 f_substitute(argvars, rettv) |
11991 typeval *argvars; | 11938 typval_T *argvars; |
11992 typeval *rettv; | 11939 typval_T *rettv; |
11993 { | 11940 { |
11994 char_u patbuf[NUMBUFLEN]; | 11941 char_u patbuf[NUMBUFLEN]; |
11995 char_u subbuf[NUMBUFLEN]; | 11942 char_u subbuf[NUMBUFLEN]; |
11996 char_u flagsbuf[NUMBUFLEN]; | 11943 char_u flagsbuf[NUMBUFLEN]; |
11997 | 11944 |
12007 * "synID(line, col, trans)" function | 11954 * "synID(line, col, trans)" function |
12008 */ | 11955 */ |
12009 /*ARGSUSED*/ | 11956 /*ARGSUSED*/ |
12010 static void | 11957 static void |
12011 f_synID(argvars, rettv) | 11958 f_synID(argvars, rettv) |
12012 typeval *argvars; | 11959 typval_T *argvars; |
12013 typeval *rettv; | 11960 typval_T *rettv; |
12014 { | 11961 { |
12015 int id = 0; | 11962 int id = 0; |
12016 #ifdef FEAT_SYN_HL | 11963 #ifdef FEAT_SYN_HL |
12017 long line; | 11964 long line; |
12018 long col; | 11965 long col; |
12034 * "synIDattr(id, what [, mode])" function | 11981 * "synIDattr(id, what [, mode])" function |
12035 */ | 11982 */ |
12036 /*ARGSUSED*/ | 11983 /*ARGSUSED*/ |
12037 static void | 11984 static void |
12038 f_synIDattr(argvars, rettv) | 11985 f_synIDattr(argvars, rettv) |
12039 typeval *argvars; | 11986 typval_T *argvars; |
12040 typeval *rettv; | 11987 typval_T *rettv; |
12041 { | 11988 { |
12042 char_u *p = NULL; | 11989 char_u *p = NULL; |
12043 #ifdef FEAT_SYN_HL | 11990 #ifdef FEAT_SYN_HL |
12044 int id; | 11991 int id; |
12045 char_u *what; | 11992 char_u *what; |
12122 * "synIDtrans(id)" function | 12069 * "synIDtrans(id)" function |
12123 */ | 12070 */ |
12124 /*ARGSUSED*/ | 12071 /*ARGSUSED*/ |
12125 static void | 12072 static void |
12126 f_synIDtrans(argvars, rettv) | 12073 f_synIDtrans(argvars, rettv) |
12127 typeval *argvars; | 12074 typval_T *argvars; |
12128 typeval *rettv; | 12075 typval_T *rettv; |
12129 { | 12076 { |
12130 int id; | 12077 int id; |
12131 | 12078 |
12132 #ifdef FEAT_SYN_HL | 12079 #ifdef FEAT_SYN_HL |
12133 id = get_tv_number(&argvars[0]); | 12080 id = get_tv_number(&argvars[0]); |
12144 /* | 12091 /* |
12145 * "system()" function | 12092 * "system()" function |
12146 */ | 12093 */ |
12147 static void | 12094 static void |
12148 f_system(argvars, rettv) | 12095 f_system(argvars, rettv) |
12149 typeval *argvars; | 12096 typval_T *argvars; |
12150 typeval *rettv; | 12097 typval_T *rettv; |
12151 { | 12098 { |
12152 char_u *res = NULL; | 12099 char_u *res = NULL; |
12153 char_u *p; | 12100 char_u *p; |
12154 char_u *infile = NULL; | 12101 char_u *infile = NULL; |
12155 char_u buf[NUMBUFLEN]; | 12102 char_u buf[NUMBUFLEN]; |
12233 * "tempname()" function | 12180 * "tempname()" function |
12234 */ | 12181 */ |
12235 /*ARGSUSED*/ | 12182 /*ARGSUSED*/ |
12236 static void | 12183 static void |
12237 f_tempname(argvars, rettv) | 12184 f_tempname(argvars, rettv) |
12238 typeval *argvars; | 12185 typval_T *argvars; |
12239 typeval *rettv; | 12186 typval_T *rettv; |
12240 { | 12187 { |
12241 static int x = 'A'; | 12188 static int x = 'A'; |
12242 | 12189 |
12243 rettv->v_type = VAR_STRING; | 12190 rettv->v_type = VAR_STRING; |
12244 rettv->vval.v_string = vim_tempname(x); | 12191 rettv->vval.v_string = vim_tempname(x); |
12268 /* | 12215 /* |
12269 * "tolower(string)" function | 12216 * "tolower(string)" function |
12270 */ | 12217 */ |
12271 static void | 12218 static void |
12272 f_tolower(argvars, rettv) | 12219 f_tolower(argvars, rettv) |
12273 typeval *argvars; | 12220 typval_T *argvars; |
12274 typeval *rettv; | 12221 typval_T *rettv; |
12275 { | 12222 { |
12276 char_u *p; | 12223 char_u *p; |
12277 | 12224 |
12278 p = vim_strsave(get_tv_string(&argvars[0])); | 12225 p = vim_strsave(get_tv_string(&argvars[0])); |
12279 rettv->v_type = VAR_STRING; | 12226 rettv->v_type = VAR_STRING; |
12311 /* | 12258 /* |
12312 * "toupper(string)" function | 12259 * "toupper(string)" function |
12313 */ | 12260 */ |
12314 static void | 12261 static void |
12315 f_toupper(argvars, rettv) | 12262 f_toupper(argvars, rettv) |
12316 typeval *argvars; | 12263 typval_T *argvars; |
12317 typeval *rettv; | 12264 typval_T *rettv; |
12318 { | 12265 { |
12319 char_u *p; | 12266 char_u *p; |
12320 | 12267 |
12321 p = vim_strsave(get_tv_string(&argvars[0])); | 12268 p = vim_strsave(get_tv_string(&argvars[0])); |
12322 rettv->v_type = VAR_STRING; | 12269 rettv->v_type = VAR_STRING; |
12354 /* | 12301 /* |
12355 * "tr(string, fromstr, tostr)" function | 12302 * "tr(string, fromstr, tostr)" function |
12356 */ | 12303 */ |
12357 static void | 12304 static void |
12358 f_tr(argvars, rettv) | 12305 f_tr(argvars, rettv) |
12359 typeval *argvars; | 12306 typval_T *argvars; |
12360 typeval *rettv; | 12307 typval_T *rettv; |
12361 { | 12308 { |
12362 char_u *instr; | 12309 char_u *instr; |
12363 char_u *fromstr; | 12310 char_u *fromstr; |
12364 char_u *tostr; | 12311 char_u *tostr; |
12365 char_u *p; | 12312 char_u *p; |
12471 /* | 12418 /* |
12472 * "type(expr)" function | 12419 * "type(expr)" function |
12473 */ | 12420 */ |
12474 static void | 12421 static void |
12475 f_type(argvars, rettv) | 12422 f_type(argvars, rettv) |
12476 typeval *argvars; | 12423 typval_T *argvars; |
12477 typeval *rettv; | 12424 typval_T *rettv; |
12478 { | 12425 { |
12479 int n; | 12426 int n; |
12480 | 12427 |
12481 switch (argvars[0].v_type) | 12428 switch (argvars[0].v_type) |
12482 { | 12429 { |
12492 /* | 12439 /* |
12493 * "values(dict)" function | 12440 * "values(dict)" function |
12494 */ | 12441 */ |
12495 static void | 12442 static void |
12496 f_values(argvars, rettv) | 12443 f_values(argvars, rettv) |
12497 typeval *argvars; | 12444 typval_T *argvars; |
12498 typeval *rettv; | 12445 typval_T *rettv; |
12499 { | 12446 { |
12500 dict_list(argvars, rettv, 1); | 12447 dict_list(argvars, rettv, 1); |
12501 } | 12448 } |
12502 | 12449 |
12503 /* | 12450 /* |
12504 * "virtcol(string)" function | 12451 * "virtcol(string)" function |
12505 */ | 12452 */ |
12506 static void | 12453 static void |
12507 f_virtcol(argvars, rettv) | 12454 f_virtcol(argvars, rettv) |
12508 typeval *argvars; | 12455 typval_T *argvars; |
12509 typeval *rettv; | 12456 typval_T *rettv; |
12510 { | 12457 { |
12511 colnr_T vcol = 0; | 12458 colnr_T vcol = 0; |
12512 pos_T *fp; | 12459 pos_T *fp; |
12513 | 12460 |
12514 fp = var2fpos(&argvars[0], FALSE); | 12461 fp = var2fpos(&argvars[0], FALSE); |
12525 * "visualmode()" function | 12472 * "visualmode()" function |
12526 */ | 12473 */ |
12527 /*ARGSUSED*/ | 12474 /*ARGSUSED*/ |
12528 static void | 12475 static void |
12529 f_visualmode(argvars, rettv) | 12476 f_visualmode(argvars, rettv) |
12530 typeval *argvars; | 12477 typval_T *argvars; |
12531 typeval *rettv; | 12478 typval_T *rettv; |
12532 { | 12479 { |
12533 #ifdef FEAT_VISUAL | 12480 #ifdef FEAT_VISUAL |
12534 char_u str[2]; | 12481 char_u str[2]; |
12535 | 12482 |
12536 rettv->v_type = VAR_STRING; | 12483 rettv->v_type = VAR_STRING; |
12552 /* | 12499 /* |
12553 * "winbufnr(nr)" function | 12500 * "winbufnr(nr)" function |
12554 */ | 12501 */ |
12555 static void | 12502 static void |
12556 f_winbufnr(argvars, rettv) | 12503 f_winbufnr(argvars, rettv) |
12557 typeval *argvars; | 12504 typval_T *argvars; |
12558 typeval *rettv; | 12505 typval_T *rettv; |
12559 { | 12506 { |
12560 win_T *wp; | 12507 win_T *wp; |
12561 | 12508 |
12562 wp = find_win_by_nr(&argvars[0]); | 12509 wp = find_win_by_nr(&argvars[0]); |
12563 if (wp == NULL) | 12510 if (wp == NULL) |
12570 * "wincol()" function | 12517 * "wincol()" function |
12571 */ | 12518 */ |
12572 /*ARGSUSED*/ | 12519 /*ARGSUSED*/ |
12573 static void | 12520 static void |
12574 f_wincol(argvars, rettv) | 12521 f_wincol(argvars, rettv) |
12575 typeval *argvars; | 12522 typval_T *argvars; |
12576 typeval *rettv; | 12523 typval_T *rettv; |
12577 { | 12524 { |
12578 validate_cursor(); | 12525 validate_cursor(); |
12579 rettv->vval.v_number = curwin->w_wcol + 1; | 12526 rettv->vval.v_number = curwin->w_wcol + 1; |
12580 } | 12527 } |
12581 | 12528 |
12582 /* | 12529 /* |
12583 * "winheight(nr)" function | 12530 * "winheight(nr)" function |
12584 */ | 12531 */ |
12585 static void | 12532 static void |
12586 f_winheight(argvars, rettv) | 12533 f_winheight(argvars, rettv) |
12587 typeval *argvars; | 12534 typval_T *argvars; |
12588 typeval *rettv; | 12535 typval_T *rettv; |
12589 { | 12536 { |
12590 win_T *wp; | 12537 win_T *wp; |
12591 | 12538 |
12592 wp = find_win_by_nr(&argvars[0]); | 12539 wp = find_win_by_nr(&argvars[0]); |
12593 if (wp == NULL) | 12540 if (wp == NULL) |
12600 * "winline()" function | 12547 * "winline()" function |
12601 */ | 12548 */ |
12602 /*ARGSUSED*/ | 12549 /*ARGSUSED*/ |
12603 static void | 12550 static void |
12604 f_winline(argvars, rettv) | 12551 f_winline(argvars, rettv) |
12605 typeval *argvars; | 12552 typval_T *argvars; |
12606 typeval *rettv; | 12553 typval_T *rettv; |
12607 { | 12554 { |
12608 validate_cursor(); | 12555 validate_cursor(); |
12609 rettv->vval.v_number = curwin->w_wrow + 1; | 12556 rettv->vval.v_number = curwin->w_wrow + 1; |
12610 } | 12557 } |
12611 | 12558 |
12613 * "winnr()" function | 12560 * "winnr()" function |
12614 */ | 12561 */ |
12615 /* ARGSUSED */ | 12562 /* ARGSUSED */ |
12616 static void | 12563 static void |
12617 f_winnr(argvars, rettv) | 12564 f_winnr(argvars, rettv) |
12618 typeval *argvars; | 12565 typval_T *argvars; |
12619 typeval *rettv; | 12566 typval_T *rettv; |
12620 { | 12567 { |
12621 int nr = 1; | 12568 int nr = 1; |
12622 #ifdef FEAT_WINDOWS | 12569 #ifdef FEAT_WINDOWS |
12623 win_T *wp; | 12570 win_T *wp; |
12624 win_T *twin = curwin; | 12571 win_T *twin = curwin; |
12653 * "winrestcmd()" function | 12600 * "winrestcmd()" function |
12654 */ | 12601 */ |
12655 /* ARGSUSED */ | 12602 /* ARGSUSED */ |
12656 static void | 12603 static void |
12657 f_winrestcmd(argvars, rettv) | 12604 f_winrestcmd(argvars, rettv) |
12658 typeval *argvars; | 12605 typval_T *argvars; |
12659 typeval *rettv; | 12606 typval_T *rettv; |
12660 { | 12607 { |
12661 #ifdef FEAT_WINDOWS | 12608 #ifdef FEAT_WINDOWS |
12662 win_T *wp; | 12609 win_T *wp; |
12663 int winnr = 1; | 12610 int winnr = 1; |
12664 garray_T ga; | 12611 garray_T ga; |
12687 /* | 12634 /* |
12688 * "winwidth(nr)" function | 12635 * "winwidth(nr)" function |
12689 */ | 12636 */ |
12690 static void | 12637 static void |
12691 f_winwidth(argvars, rettv) | 12638 f_winwidth(argvars, rettv) |
12692 typeval *argvars; | 12639 typval_T *argvars; |
12693 typeval *rettv; | 12640 typval_T *rettv; |
12694 { | 12641 { |
12695 win_T *wp; | 12642 win_T *wp; |
12696 | 12643 |
12697 wp = find_win_by_nr(&argvars[0]); | 12644 wp = find_win_by_nr(&argvars[0]); |
12698 if (wp == NULL) | 12645 if (wp == NULL) |
12705 #endif | 12652 #endif |
12706 } | 12653 } |
12707 | 12654 |
12708 static win_T * | 12655 static win_T * |
12709 find_win_by_nr(vp) | 12656 find_win_by_nr(vp) |
12710 typeval *vp; | 12657 typval_T *vp; |
12711 { | 12658 { |
12712 #ifdef FEAT_WINDOWS | 12659 #ifdef FEAT_WINDOWS |
12713 win_T *wp; | 12660 win_T *wp; |
12714 #endif | 12661 #endif |
12715 int nr; | 12662 int nr; |
12734 /* | 12681 /* |
12735 * Translate a String variable into a position. | 12682 * Translate a String variable into a position. |
12736 */ | 12683 */ |
12737 static pos_T * | 12684 static pos_T * |
12738 var2fpos(varp, lnum) | 12685 var2fpos(varp, lnum) |
12739 typeval *varp; | 12686 typval_T *varp; |
12740 int lnum; /* TRUE when $ is last line */ | 12687 int lnum; /* TRUE when $ is last line */ |
12741 { | 12688 { |
12742 char_u *name; | 12689 char_u *name; |
12743 static pos_T pos; | 12690 static pos_T pos; |
12744 pos_T *pp; | 12691 pos_T *pp; |
12950 static int | 12897 static int |
12951 eval_isnamec(c) | 12898 eval_isnamec(c) |
12952 int c; | 12899 int c; |
12953 { | 12900 { |
12954 return (ASCII_ISALNUM(c) || c == '_' || c == ':'); | 12901 return (ASCII_ISALNUM(c) || c == '_' || c == ':'); |
12955 } | |
12956 | |
12957 /* | |
12958 * Find a v: variable. | |
12959 * Return it's index, or -1 if not found. | |
12960 */ | |
12961 static int | |
12962 find_vim_var(name, len) | |
12963 char_u *name; | |
12964 int len; /* length of "name" */ | |
12965 { | |
12966 char_u *vname; | |
12967 int vlen; | |
12968 int i; | |
12969 | |
12970 /* | |
12971 * Ignore "v:" for old built-in variables, require it for new ones. | |
12972 */ | |
12973 if (name[0] == 'v' && name[1] == ':') | |
12974 { | |
12975 vname = name + 2; | |
12976 vlen = len - 2; | |
12977 } | |
12978 else | |
12979 { | |
12980 vname = name; | |
12981 vlen = len; | |
12982 } | |
12983 for (i = 0; i < VV_LEN; ++i) | |
12984 if (vlen == vimvars[i].len && STRCMP(vname, vimvars[i].name) == 0 | |
12985 && ((vimvars[i].flags & VV_COMPAT) || vname != name)) | |
12986 return i; | |
12987 return -1; | |
12988 } | 12902 } |
12989 | 12903 |
12990 /* | 12904 /* |
12991 * Set number v: variable to "val". | 12905 * Set number v: variable to "val". |
12992 */ | 12906 */ |
13161 */ | 13075 */ |
13162 static int | 13076 static int |
13163 get_var_tv(name, len, rettv) | 13077 get_var_tv(name, len, rettv) |
13164 char_u *name; | 13078 char_u *name; |
13165 int len; /* length of "name" */ | 13079 int len; /* length of "name" */ |
13166 typeval *rettv; /* NULL when only checking existence */ | 13080 typval_T *rettv; /* NULL when only checking existence */ |
13167 { | 13081 { |
13168 int ret = OK; | 13082 int ret = OK; |
13169 typeval *tv = NULL; | 13083 typval_T *tv = NULL; |
13170 typeval atv; | 13084 typval_T atv; |
13171 VAR v; | 13085 dictitem_T *v; |
13172 int cc; | 13086 int cc; |
13173 int i; | |
13174 | 13087 |
13175 /* truncate the name, so that we can use strcmp() */ | 13088 /* truncate the name, so that we can use strcmp() */ |
13176 cc = name[len]; | 13089 cc = name[len]; |
13177 name[len] = NUL; | 13090 name[len] = NUL; |
13178 | 13091 |
13185 atv.vval.v_number = curbuf->b_changedtick; | 13098 atv.vval.v_number = curbuf->b_changedtick; |
13186 tv = &atv; | 13099 tv = &atv; |
13187 } | 13100 } |
13188 | 13101 |
13189 /* | 13102 /* |
13190 * Check for built-in v: variables. | |
13191 */ | |
13192 else if ((i = find_vim_var(name, len)) >= 0) | |
13193 tv = &vimvars[i].tv; | |
13194 | |
13195 /* | |
13196 * Check for user-defined variables. | 13103 * Check for user-defined variables. |
13197 */ | 13104 */ |
13198 else | 13105 else |
13199 { | 13106 { |
13200 v = find_var(name, NULL); | 13107 v = find_var(name, NULL); |
13201 if (v != NULL) | 13108 if (v != NULL) |
13202 tv = &v->tv; | 13109 tv = &v->di_tv; |
13203 } | 13110 } |
13204 | 13111 |
13205 if (tv == NULL) | 13112 if (tv == NULL) |
13206 { | 13113 { |
13207 if (rettv != NULL) | 13114 if (rettv != NULL) |
13218 | 13125 |
13219 /* | 13126 /* |
13220 * Allocate memory for a variable type-value, and make it emtpy (0 or NULL | 13127 * Allocate memory for a variable type-value, and make it emtpy (0 or NULL |
13221 * value). | 13128 * value). |
13222 */ | 13129 */ |
13223 static typeval * | 13130 static typval_T * |
13224 alloc_tv() | 13131 alloc_tv() |
13225 { | 13132 { |
13226 return (typeval *)alloc_clear((unsigned)sizeof(typeval)); | 13133 return (typval_T *)alloc_clear((unsigned)sizeof(typval_T)); |
13227 } | 13134 } |
13228 | 13135 |
13229 /* | 13136 /* |
13230 * Allocate memory for a variable type-value, and assign a string to it. | 13137 * Allocate memory for a variable type-value, and assign a string to it. |
13231 * The string "s" must have been allocated, it is consumed. | 13138 * The string "s" must have been allocated, it is consumed. |
13232 * Return NULL for out of memory, the variable otherwise. | 13139 * Return NULL for out of memory, the variable otherwise. |
13233 */ | 13140 */ |
13234 static typeval * | 13141 static typval_T * |
13235 alloc_string_tv(s) | 13142 alloc_string_tv(s) |
13236 char_u *s; | 13143 char_u *s; |
13237 { | 13144 { |
13238 typeval *rettv; | 13145 typval_T *rettv; |
13239 | 13146 |
13240 rettv = alloc_tv(); | 13147 rettv = alloc_tv(); |
13241 if (rettv != NULL) | 13148 if (rettv != NULL) |
13242 { | 13149 { |
13243 rettv->v_type = VAR_STRING; | 13150 rettv->v_type = VAR_STRING; |
13251 /* | 13158 /* |
13252 * Free the memory for a variable type-value. | 13159 * Free the memory for a variable type-value. |
13253 */ | 13160 */ |
13254 static void | 13161 static void |
13255 free_tv(varp) | 13162 free_tv(varp) |
13256 typeval *varp; | 13163 typval_T *varp; |
13257 { | 13164 { |
13258 if (varp != NULL) | 13165 if (varp != NULL) |
13259 { | 13166 { |
13260 switch (varp->v_type) | 13167 switch (varp->v_type) |
13261 { | 13168 { |
13281 /* | 13188 /* |
13282 * Free the memory for a variable value and set the value to NULL or 0. | 13189 * Free the memory for a variable value and set the value to NULL or 0. |
13283 */ | 13190 */ |
13284 static void | 13191 static void |
13285 clear_tv(varp) | 13192 clear_tv(varp) |
13286 typeval *varp; | 13193 typval_T *varp; |
13287 { | 13194 { |
13288 if (varp != NULL) | 13195 if (varp != NULL) |
13289 { | 13196 { |
13290 switch (varp->v_type) | 13197 switch (varp->v_type) |
13291 { | 13198 { |
13318 /* | 13225 /* |
13319 * Set the value of a variable to NULL without freeing items. | 13226 * Set the value of a variable to NULL without freeing items. |
13320 */ | 13227 */ |
13321 static void | 13228 static void |
13322 init_tv(varp) | 13229 init_tv(varp) |
13323 typeval *varp; | 13230 typval_T *varp; |
13324 { | 13231 { |
13325 if (varp != NULL) | 13232 if (varp != NULL) |
13326 vim_memset(varp, 0, sizeof(typeval)); | 13233 vim_memset(varp, 0, sizeof(typval_T)); |
13327 } | 13234 } |
13328 | 13235 |
13329 /* | 13236 /* |
13330 * Get the number value of a variable. | 13237 * Get the number value of a variable. |
13331 * If it is a String variable, uses vim_str2nr(). | 13238 * If it is a String variable, uses vim_str2nr(). |
13332 */ | 13239 */ |
13333 static long | 13240 static long |
13334 get_tv_number(varp) | 13241 get_tv_number(varp) |
13335 typeval *varp; | 13242 typval_T *varp; |
13336 { | 13243 { |
13337 long n = 0L; | 13244 long n = 0L; |
13338 | 13245 |
13339 switch (varp->v_type) | 13246 switch (varp->v_type) |
13340 { | 13247 { |
13365 /* | 13272 /* |
13366 * Get the lnum from the first argument. Also accepts ".", "$", etc. | 13273 * Get the lnum from the first argument. Also accepts ".", "$", etc. |
13367 */ | 13274 */ |
13368 static linenr_T | 13275 static linenr_T |
13369 get_tv_lnum(argvars) | 13276 get_tv_lnum(argvars) |
13370 typeval *argvars; | 13277 typval_T *argvars; |
13371 { | 13278 { |
13372 typeval rettv; | 13279 typval_T rettv; |
13373 linenr_T lnum; | 13280 linenr_T lnum; |
13374 | 13281 |
13375 lnum = get_tv_number(&argvars[0]); | 13282 lnum = get_tv_number(&argvars[0]); |
13376 if (lnum == 0) /* no valid number, try using line() */ | 13283 if (lnum == 0) /* no valid number, try using line() */ |
13377 { | 13284 { |
13391 * If the String variable has never been set, return an empty string. | 13298 * If the String variable has never been set, return an empty string. |
13392 * Never returns NULL; | 13299 * Never returns NULL; |
13393 */ | 13300 */ |
13394 static char_u * | 13301 static char_u * |
13395 get_tv_string(varp) | 13302 get_tv_string(varp) |
13396 typeval *varp; | 13303 typval_T *varp; |
13397 { | 13304 { |
13398 static char_u mybuf[NUMBUFLEN]; | 13305 static char_u mybuf[NUMBUFLEN]; |
13399 | 13306 |
13400 return get_tv_string_buf(varp, mybuf); | 13307 return get_tv_string_buf(varp, mybuf); |
13401 } | 13308 } |
13402 | 13309 |
13403 static char_u * | 13310 static char_u * |
13404 get_tv_string_buf(varp, buf) | 13311 get_tv_string_buf(varp, buf) |
13405 typeval *varp; | 13312 typval_T *varp; |
13406 char_u *buf; | 13313 char_u *buf; |
13407 { | 13314 { |
13408 switch (varp->v_type) | 13315 switch (varp->v_type) |
13409 { | 13316 { |
13410 case VAR_NUMBER: | 13317 case VAR_NUMBER: |
13433 /* | 13340 /* |
13434 * Find variable "name" in the list of variables. | 13341 * Find variable "name" in the list of variables. |
13435 * Return a pointer to it if found, NULL if not found. | 13342 * Return a pointer to it if found, NULL if not found. |
13436 * Careful: "a:0" variables don't have a name. | 13343 * Careful: "a:0" variables don't have a name. |
13437 * When "htp" is not NULL we are writing to the variable, set "htp" to the | 13344 * When "htp" is not NULL we are writing to the variable, set "htp" to the |
13438 * hashtable used. | 13345 * hashtab_T used. |
13439 */ | 13346 */ |
13440 static VAR | 13347 static dictitem_T * |
13441 find_var(name, htp) | 13348 find_var(name, htp) |
13442 char_u *name; | 13349 char_u *name; |
13443 hashtable **htp; | 13350 hashtab_T **htp; |
13444 { | 13351 { |
13445 int i; | |
13446 char_u *varname; | 13352 char_u *varname; |
13447 hashtable *ht; | 13353 hashtab_T *ht; |
13448 | |
13449 if (name[0] == 'a' && name[1] == ':') | |
13450 { | |
13451 /* Function arguments "a:". | |
13452 * NOTE: We use a typecast, because function arguments don't have a | |
13453 * name. The caller must not try to access the name! */ | |
13454 if (htp != NULL) | |
13455 { | |
13456 EMSG2(_(e_readonlyvar), name); | |
13457 return NULL; | |
13458 } | |
13459 name += 2; | |
13460 if (current_funccal == NULL) | |
13461 return NULL; | |
13462 if (VIM_ISDIGIT(*name)) | |
13463 { | |
13464 i = atol((char *)name); | |
13465 if (i == 0) /* a:0 */ | |
13466 return ¤t_funccal->a0_var; | |
13467 i += current_funccal->func->args.ga_len; | |
13468 if (i > current_funccal->argcount) /* a:999 */ | |
13469 return NULL; | |
13470 return (VAR)&(current_funccal->argvars[i - 1]); /* a:1, a:2, etc. */ | |
13471 } | |
13472 if (STRCMP(name, "firstline") == 0) | |
13473 return &(current_funccal->firstline); | |
13474 if (STRCMP(name, "lastline") == 0) | |
13475 return &(current_funccal->lastline); | |
13476 for (i = 0; i < current_funccal->func->args.ga_len; ++i) | |
13477 if (STRCMP(name, ((char_u **) | |
13478 (current_funccal->func->args.ga_data))[i]) == 0) | |
13479 return (VAR)&(current_funccal->argvars[i]); /* a:name */ | |
13480 return NULL; | |
13481 } | |
13482 | 13354 |
13483 ht = find_var_ht(name, &varname); | 13355 ht = find_var_ht(name, &varname); |
13484 if (htp != NULL) | 13356 if (htp != NULL) |
13485 *htp = ht; | 13357 *htp = ht; |
13486 if (ht == NULL) | 13358 if (ht == NULL) |
13487 return NULL; | 13359 return NULL; |
13488 return find_var_in_ht(ht, varname); | 13360 return find_var_in_ht(ht, varname); |
13489 } | 13361 } |
13490 | 13362 |
13491 /* | 13363 /* |
13492 * Find variable "varname" in hashtable "ht". | 13364 * Find variable "varname" in hashtab "ht". |
13493 * Returns NULL if not found. | 13365 * Returns NULL if not found. |
13494 */ | 13366 */ |
13495 static VAR | 13367 static dictitem_T * |
13496 find_var_in_ht(ht, varname) | 13368 find_var_in_ht(ht, varname) |
13497 hashtable *ht; | 13369 hashtab_T *ht; |
13498 char_u *varname; | 13370 char_u *varname; |
13499 { | 13371 { |
13500 hashitem *hi; | 13372 hashitem_T *hi; |
13373 | |
13374 if (*varname == NUL) | |
13375 { | |
13376 /* Must be something like "s:", otherwise "ht" would be NULL. */ | |
13377 switch (varname[-2]) | |
13378 { | |
13379 case 's': return &SCRIPT_SV(current_SID).sv_var; | |
13380 case 'g': return &globvars_var; | |
13381 case 'v': return &vimvars_var; | |
13382 case 'b': return &curbuf->b_bufvar; | |
13383 case 'w': return &curwin->w_winvar; | |
13384 case 'l': return ¤t_funccal->l_vars_var; | |
13385 case 'a': return ¤t_funccal->l_avars_var; | |
13386 } | |
13387 return NULL; | |
13388 } | |
13501 | 13389 |
13502 hi = hash_find(ht, varname); | 13390 hi = hash_find(ht, varname); |
13503 if (HASHITEM_EMPTY(hi)) | 13391 if (HASHITEM_EMPTY(hi)) |
13504 return NULL; | 13392 return NULL; |
13505 return HI2VAR(hi); | 13393 return HI2DI(hi); |
13506 } | 13394 } |
13507 | 13395 |
13508 /* | 13396 /* |
13509 * Find the hashtable used for a variable name. | 13397 * Find the hashtab used for a variable name. |
13510 * Set "varname" to the start of name without ':'. | 13398 * Set "varname" to the start of name without ':'. |
13511 */ | 13399 */ |
13512 static hashtable * | 13400 static hashtab_T * |
13513 find_var_ht(name, varname) | 13401 find_var_ht(name, varname) |
13514 char_u *name; | 13402 char_u *name; |
13515 char_u **varname; | 13403 char_u **varname; |
13516 { | 13404 { |
13517 if (name[1] != ':') | 13405 if (name[1] != ':') |
13519 /* If not "x:name" there must not be any ":" in the name. */ | 13407 /* If not "x:name" there must not be any ":" in the name. */ |
13520 if (vim_strchr(name, ':') != NULL) | 13408 if (vim_strchr(name, ':') != NULL) |
13521 return NULL; | 13409 return NULL; |
13522 *varname = name; | 13410 *varname = name; |
13523 if (current_funccal == NULL) | 13411 if (current_funccal == NULL) |
13524 return &variables; /* global variable */ | 13412 return &globvarht; /* global variable */ |
13525 return ¤t_funccal->l_vars; /* local function variable */ | 13413 return ¤t_funccal->l_vars.dv_hashtab; /* l: variable */ |
13526 } | 13414 } |
13527 *varname = name + 2; | 13415 *varname = name + 2; |
13528 if (*name == 'b') /* buffer variable */ | 13416 if (*name == 'b') /* buffer variable */ |
13529 return &curbuf->b_vars; | 13417 return &curbuf->b_vars.dv_hashtab; |
13530 if (*name == 'w') /* window variable */ | 13418 if (*name == 'w') /* window variable */ |
13531 return &curwin->w_vars; | 13419 return &curwin->w_vars.dv_hashtab; |
13532 if (*name == 'g') /* global variable */ | 13420 if (*name == 'g') /* global variable */ |
13533 return &variables; | 13421 return &globvarht; |
13534 if (*name == 'l' && current_funccal != NULL)/* local function variable */ | 13422 if (*name == 'v') /* v: variable */ |
13535 return ¤t_funccal->l_vars; | 13423 return &vimvarht; |
13424 if (*name == 'a' && current_funccal != NULL) /* function argument */ | |
13425 return ¤t_funccal->l_avars.dv_hashtab; | |
13426 if (*name == 'l' && current_funccal != NULL) /* local function variable */ | |
13427 return ¤t_funccal->l_vars.dv_hashtab; | |
13536 if (*name == 's' /* script variable */ | 13428 if (*name == 's' /* script variable */ |
13537 && current_SID > 0 && current_SID <= ga_scripts.ga_len) | 13429 && current_SID > 0 && current_SID <= ga_scripts.ga_len) |
13538 return &SCRIPT_VARS(current_SID); | 13430 return &SCRIPT_VARS(current_SID); |
13539 return NULL; | 13431 return NULL; |
13540 } | 13432 } |
13545 */ | 13437 */ |
13546 char_u * | 13438 char_u * |
13547 get_var_value(name) | 13439 get_var_value(name) |
13548 char_u *name; | 13440 char_u *name; |
13549 { | 13441 { |
13550 VAR v; | 13442 dictitem_T *v; |
13551 | 13443 |
13552 v = find_var(name, NULL); | 13444 v = find_var(name, NULL); |
13553 if (v == NULL) | 13445 if (v == NULL) |
13554 return NULL; | 13446 return NULL; |
13555 return get_tv_string(&v->tv); | 13447 return get_tv_string(&v->di_tv); |
13556 } | 13448 } |
13557 | 13449 |
13558 /* | 13450 /* |
13559 * Allocate a new hashtable for a sourced script. It will be used while | 13451 * Allocate a new hashtab for a sourced script. It will be used while |
13560 * sourcing this script and when executing functions defined in the script. | 13452 * sourcing this script and when executing functions defined in the script. |
13561 */ | 13453 */ |
13562 void | 13454 void |
13563 new_script_vars(id) | 13455 new_script_vars(id) |
13564 scid_T id; | 13456 scid_T id; |
13565 { | 13457 { |
13566 int i; | 13458 int i; |
13567 hashtable *ht; | 13459 hashtab_T *ht; |
13460 scriptvar_T *sv; | |
13568 | 13461 |
13569 if (ga_grow(&ga_scripts, (int)(id - ga_scripts.ga_len)) == OK) | 13462 if (ga_grow(&ga_scripts, (int)(id - ga_scripts.ga_len)) == OK) |
13570 { | 13463 { |
13571 /* Re-allocating ga_data means that an ht_array pointing to | 13464 /* Re-allocating ga_data means that an ht_array pointing to |
13572 * ht_smallarray becomes invalid. We can recognize this: ht_mask is | 13465 * ht_smallarray becomes invalid. We can recognize this: ht_mask is |
13573 * at its init value. */ | 13466 * at its init value. Also reset "v_dict", it's always the same. */ |
13574 for (i = 1; i <= ga_scripts.ga_len; ++i) | 13467 for (i = 1; i <= ga_scripts.ga_len; ++i) |
13575 { | 13468 { |
13576 ht = &SCRIPT_VARS(i); | 13469 ht = &SCRIPT_VARS(i); |
13577 if (ht->ht_mask == HT_INIT_SIZE - 1) | 13470 if (ht->ht_mask == HT_INIT_SIZE - 1) |
13578 ht->ht_array = ht->ht_smallarray; | 13471 ht->ht_array = ht->ht_smallarray; |
13472 sv = &SCRIPT_SV(i); | |
13473 sv->sv_var.di_tv.vval.v_dict = &sv->sv_dict; | |
13579 } | 13474 } |
13580 | 13475 |
13581 while (ga_scripts.ga_len < id) | 13476 while (ga_scripts.ga_len < id) |
13582 { | 13477 { |
13583 vars_init(&SCRIPT_VARS(ga_scripts.ga_len + 1)); | 13478 sv = &SCRIPT_SV(ga_scripts.ga_len + 1); |
13479 init_var_dict(&sv->sv_dict, &sv->sv_var); | |
13584 ++ga_scripts.ga_len; | 13480 ++ga_scripts.ga_len; |
13585 } | 13481 } |
13586 } | 13482 } |
13587 } | 13483 } |
13588 | 13484 |
13589 /* | 13485 /* |
13590 * Initialize hashtable with variables for use. | 13486 * Initialize dictionary "dict" as a scope and set variable "dict_var" to |
13487 * point to it. | |
13591 */ | 13488 */ |
13592 void | 13489 void |
13593 vars_init(ht) | 13490 init_var_dict(dict, dict_var) |
13594 hashtable *ht; | 13491 dict_T *dict; |
13595 { | 13492 dictitem_T *dict_var; |
13596 hash_init(ht); | 13493 { |
13494 hash_init(&dict->dv_hashtab); | |
13495 dict->dv_refcount = 99999; | |
13496 dict_var->di_tv.vval.v_dict = dict; | |
13497 dict_var->di_tv.v_type = VAR_DICT; | |
13498 dict_var->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; | |
13499 dict_var->di_key[0] = NUL; | |
13597 } | 13500 } |
13598 | 13501 |
13599 /* | 13502 /* |
13600 * Clean up a list of internal variables. | 13503 * Clean up a list of internal variables. |
13504 * Frees all allocated variables and the value they contain. | |
13505 * Clears hashtab "ht", does not free it. | |
13601 */ | 13506 */ |
13602 void | 13507 void |
13603 vars_clear(ht) | 13508 vars_clear(ht) |
13604 hashtable *ht; | 13509 hashtab_T *ht; |
13510 { | |
13511 vars_clear_ext(ht, TRUE); | |
13512 } | |
13513 | |
13514 /* | |
13515 * Like vars_clear(), but only free the value if "free_val" is TRUE. | |
13516 */ | |
13517 static void | |
13518 vars_clear_ext(ht, free_val) | |
13519 hashtab_T *ht; | |
13520 int free_val; | |
13605 { | 13521 { |
13606 int todo; | 13522 int todo; |
13607 hashitem *hi; | 13523 hashitem_T *hi; |
13608 VAR v; | 13524 dictitem_T *v; |
13609 | 13525 |
13526 hash_lock(ht); | |
13610 todo = ht->ht_used; | 13527 todo = ht->ht_used; |
13611 for (hi = ht->ht_array; todo > 0; ++hi) | 13528 for (hi = ht->ht_array; todo > 0; ++hi) |
13612 { | 13529 { |
13613 if (!HASHITEM_EMPTY(hi)) | 13530 if (!HASHITEM_EMPTY(hi)) |
13614 { | 13531 { |
13615 --todo; | 13532 --todo; |
13616 | 13533 |
13617 /* Free the variable. Don't remove it from the hashtable, | 13534 /* Free the variable. Don't remove it from the hashtab, |
13618 * ht_array might change then. hash_clear() takes care of it | 13535 * ht_array might change then. hash_clear() takes care of it |
13619 * later. */ | 13536 * later. */ |
13620 v = HI2VAR(hi); | 13537 v = HI2DI(hi); |
13621 clear_tv(&v->tv); | 13538 if (free_val) |
13622 vim_free(v); | 13539 clear_tv(&v->di_tv); |
13540 if ((v->di_flags & DI_FLAGS_FIX) == 0) | |
13541 vim_free(v); | |
13623 } | 13542 } |
13624 } | 13543 } |
13625 hash_clear(ht); | 13544 hash_clear(ht); |
13626 hash_init(ht); | 13545 } |
13627 } | 13546 |
13628 | 13547 /* |
13629 /* | 13548 * Delete a variable from hashtab "ht" at item "hi". |
13630 * Delete a variable from hashtable "ht" at item "hi". | 13549 * Clear the variable value and free the dictitem. |
13631 */ | 13550 */ |
13632 static void | 13551 static void |
13633 delete_var(ht, hi) | 13552 delete_var(ht, hi) |
13634 hashtable *ht; | 13553 hashtab_T *ht; |
13635 hashitem *hi; | 13554 hashitem_T *hi; |
13636 { | 13555 { |
13637 VAR v = HI2VAR(hi); | 13556 dictitem_T *di = HI2DI(hi); |
13638 | 13557 |
13639 hash_remove(ht, hi); | 13558 hash_remove(ht, hi); |
13640 clear_tv(&v->tv); | 13559 clear_tv(&di->di_tv); |
13641 vim_free(v); | 13560 vim_free(di); |
13642 } | 13561 } |
13643 | 13562 |
13644 /* | 13563 /* |
13645 * List the value of one internal variable. | 13564 * List the value of one internal variable. |
13646 */ | 13565 */ |
13647 static void | 13566 static void |
13648 list_one_var(v, prefix) | 13567 list_one_var(v, prefix) |
13649 VAR v; | 13568 dictitem_T *v; |
13650 char_u *prefix; | 13569 char_u *prefix; |
13651 { | 13570 { |
13652 char_u *tofree; | 13571 char_u *tofree; |
13653 char_u *s; | 13572 char_u *s; |
13654 char_u numbuf[NUMBUFLEN]; | 13573 char_u numbuf[NUMBUFLEN]; |
13655 | 13574 |
13656 s = echo_string(&v->tv, &tofree, numbuf); | 13575 s = echo_string(&v->di_tv, &tofree, numbuf); |
13657 list_one_var_a(prefix, v->v_name, v->tv.v_type, | 13576 list_one_var_a(prefix, v->di_key, v->di_tv.v_type, |
13658 s == NULL ? (char_u *)"" : s); | 13577 s == NULL ? (char_u *)"" : s); |
13659 vim_free(tofree); | |
13660 } | |
13661 | |
13662 /* | |
13663 * List the value of one "v:" variable. | |
13664 */ | |
13665 static void | |
13666 list_vim_var(i) | |
13667 int i; /* index in vimvars[] */ | |
13668 { | |
13669 char_u *tofree; | |
13670 char_u *s; | |
13671 char_u numbuf[NUMBUFLEN]; | |
13672 | |
13673 s = echo_string(&vimvars[i].tv, &tofree, numbuf); | |
13674 list_one_var_a((char_u *)"v:", (char_u *)vimvars[i].name, | |
13675 vimvars[i].tv.v_type, s == NULL ? (char_u *)"" : s); | |
13676 vim_free(tofree); | 13578 vim_free(tofree); |
13677 } | 13579 } |
13678 | 13580 |
13679 static void | 13581 static void |
13680 list_one_var_a(prefix, name, type, string) | 13582 list_one_var_a(prefix, name, type, string) |
13719 * Otherwise the variable is created. | 13621 * Otherwise the variable is created. |
13720 */ | 13622 */ |
13721 static void | 13623 static void |
13722 set_var(name, tv, copy) | 13624 set_var(name, tv, copy) |
13723 char_u *name; | 13625 char_u *name; |
13724 typeval *tv; | 13626 typval_T *tv; |
13725 int copy; /* make copy of value in "tv" */ | 13627 int copy; /* make copy of value in "tv" */ |
13726 { | 13628 { |
13727 int i; | 13629 dictitem_T *v; |
13728 VAR v; | |
13729 char_u *varname; | 13630 char_u *varname; |
13730 hashtable *ht; | 13631 hashtab_T *ht; |
13731 | 13632 |
13732 /* | 13633 if (tv->v_type == VAR_FUNC) |
13733 * Handle setting internal v: variables. | 13634 { |
13734 */ | 13635 if (!(vim_strchr((char_u *)"wbs", name[0]) != NULL && name[1] == ':') |
13735 i = find_vim_var(name, (int)STRLEN(name)); | 13636 && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':') |
13736 if (i >= 0) | 13637 ? name[2] : name[0])) |
13737 { | 13638 { |
13738 if (vimvars[i].flags & VV_RO) | 13639 EMSG2(_("E704: Funcref variable name must start with a capital: %s"), name); |
13739 EMSG2(_(e_readonlyvar), name); | 13640 return; |
13740 else if ((vimvars[i].flags & VV_RO_SBX) && sandbox) | 13641 } |
13741 EMSG2(_(e_readonlysbx), name); | 13642 if (function_exists(name)) |
13742 else | 13643 { |
13743 { | 13644 EMSG2(_("705: Variable name conflicts with existing function: %s"), name); |
13744 if (vimvars[i].tv.v_type == VAR_STRING) | 13645 return; |
13646 } | |
13647 } | |
13648 | |
13649 ht = find_var_ht(name, &varname); | |
13650 if (ht == NULL || *varname == NUL) | |
13651 { | |
13652 EMSG2(_("E461: Illegal variable name: %s"), name); | |
13653 return; | |
13654 } | |
13655 | |
13656 v = find_var_in_ht(ht, varname); | |
13657 if (v != NULL) | |
13658 { | |
13659 /* existing variable, need to clear the value */ | |
13660 if (var_check_ro(v->di_flags, name)) | |
13661 return; | |
13662 if (v->di_tv.v_type != tv->v_type | |
13663 && !((v->di_tv.v_type == VAR_STRING | |
13664 || v->di_tv.v_type == VAR_NUMBER) | |
13665 && (tv->v_type == VAR_STRING | |
13666 || tv->v_type == VAR_NUMBER))) | |
13667 { | |
13668 EMSG2(_("E706: Variable type mismatch for: %s"), name); | |
13669 return; | |
13670 } | |
13671 | |
13672 /* | |
13673 * Handle setting internal v: variables separately: we keep the type. | |
13674 */ | |
13675 if (ht == &vimvarht) | |
13676 { | |
13677 if (v->di_tv.v_type == VAR_STRING) | |
13745 { | 13678 { |
13746 vim_free(vimvars[i].vv_str); | 13679 vim_free(v->di_tv.vval.v_string); |
13747 if (copy || tv->v_type != VAR_STRING) | 13680 if (copy || tv->v_type != VAR_STRING) |
13748 vimvars[i].vv_str = vim_strsave(get_tv_string(tv)); | 13681 v->di_tv.vval.v_string = vim_strsave(get_tv_string(tv)); |
13749 else | 13682 else |
13750 { | 13683 { |
13751 /* Take over the string to avoid an extra alloc/free. */ | 13684 /* Take over the string to avoid an extra alloc/free. */ |
13752 vimvars[i].vv_str = tv->vval.v_string; | 13685 v->di_tv.vval.v_string = tv->vval.v_string; |
13753 tv->vval.v_string = NULL; | 13686 tv->vval.v_string = NULL; |
13754 } | 13687 } |
13755 } | 13688 } |
13689 else if (v->di_tv.v_type != VAR_NUMBER) | |
13690 EMSG2(_(e_intern2), "set_var()"); | |
13756 else | 13691 else |
13757 vimvars[i].vv_nr = get_tv_number(tv); | 13692 v->di_tv.vval.v_number = get_tv_number(tv); |
13758 } | |
13759 return; | |
13760 } | |
13761 | |
13762 if (tv->v_type == VAR_FUNC) | |
13763 { | |
13764 if (!(vim_strchr((char_u *)"wbs", name[0]) != NULL && name[1] == ':') | |
13765 && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':') | |
13766 ? name[2] : name[0])) | |
13767 { | |
13768 EMSG2(_("E704: Funcref variable name must start with a capital: %s"), name); | |
13769 return; | 13693 return; |
13770 } | 13694 } |
13771 if (function_exists(name)) | 13695 |
13772 { | 13696 clear_tv(&v->di_tv); |
13773 EMSG2(_("705: Variable name conflicts with existing function: %s"), name); | |
13774 return; | |
13775 } | |
13776 } | |
13777 | |
13778 if (name[0] == 'a' && name[1] == ':') | |
13779 { | |
13780 EMSG2(_(e_readonlyvar), name); | |
13781 return; | |
13782 } | |
13783 | |
13784 ht = find_var_ht(name, &varname); | |
13785 if (ht == NULL) | |
13786 { | |
13787 EMSG2(_("E461: Illegal variable name: %s"), name); | |
13788 return; | |
13789 } | |
13790 | |
13791 v = find_var_in_ht(ht, varname); | |
13792 if (v != NULL) /* existing variable, need to clear the value */ | |
13793 { | |
13794 if (v->tv.v_type != tv->v_type | |
13795 && !((v->tv.v_type == VAR_STRING | |
13796 || v->tv.v_type == VAR_NUMBER) | |
13797 && (tv->v_type == VAR_STRING | |
13798 || tv->v_type == VAR_NUMBER))) | |
13799 { | |
13800 EMSG2(_("E706: Variable type mismatch for: %s"), name); | |
13801 return; | |
13802 } | |
13803 clear_tv(&v->tv); | |
13804 } | 13697 } |
13805 else /* add a new variable */ | 13698 else /* add a new variable */ |
13806 { | 13699 { |
13807 v = (VAR)alloc((unsigned)(sizeof(var) + STRLEN(varname))); | 13700 v = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T) + STRLEN(varname))); |
13808 if (v == NULL) | 13701 if (v == NULL) |
13809 return; | 13702 return; |
13810 STRCPY(v->v_name, varname); | 13703 STRCPY(v->di_key, varname); |
13811 if (hash_add(ht, VAR2HIKEY(v)) == FAIL) | 13704 v->di_flags = 0; |
13705 if (hash_add(ht, DI2HIKEY(v)) == FAIL) | |
13812 { | 13706 { |
13813 vim_free(v); | 13707 vim_free(v); |
13814 return; | 13708 return; |
13815 } | 13709 } |
13816 } | 13710 } |
13817 | 13711 |
13818 if (copy || tv->v_type == VAR_NUMBER) | 13712 if (copy || tv->v_type == VAR_NUMBER) |
13819 copy_tv(tv, &v->tv); | 13713 copy_tv(tv, &v->di_tv); |
13820 else | 13714 else |
13821 { | 13715 { |
13822 v->tv = *tv; | 13716 v->di_tv = *tv; |
13823 init_tv(tv); | 13717 init_tv(tv); |
13824 } | 13718 } |
13825 } | 13719 } |
13826 | 13720 |
13827 /* | 13721 /* |
13828 * Copy the values from typeval "from" to typeval "to". | 13722 * Return TRUE if di_flags "flags" indicate read-only variable "name". |
13723 * Also give an error message. | |
13724 */ | |
13725 static int | |
13726 var_check_ro(flags, name) | |
13727 int flags; | |
13728 char_u *name; | |
13729 { | |
13730 if (flags & DI_FLAGS_RO) | |
13731 { | |
13732 EMSG2(_(e_readonlyvar), name); | |
13733 return TRUE; | |
13734 } | |
13735 if ((flags & DI_FLAGS_RO_SBX) && sandbox) | |
13736 { | |
13737 EMSG2(_(e_readonlysbx), name); | |
13738 return TRUE; | |
13739 } | |
13740 return FALSE; | |
13741 } | |
13742 | |
13743 /* | |
13744 * Copy the values from typval_T "from" to typval_T "to". | |
13829 * When needed allocates string or increases reference count. | 13745 * When needed allocates string or increases reference count. |
13830 * Does not make a copy of a list or dict but copies the reference! | 13746 * Does not make a copy of a list or dict but copies the reference! |
13831 */ | 13747 */ |
13832 static void | 13748 static void |
13833 copy_tv(from, to) | 13749 copy_tv(from, to) |
13834 typeval *from; | 13750 typval_T *from; |
13835 typeval *to; | 13751 typval_T *to; |
13836 { | 13752 { |
13837 to->v_type = from->v_type; | 13753 to->v_type = from->v_type; |
13838 switch (from->v_type) | 13754 switch (from->v_type) |
13839 { | 13755 { |
13840 case VAR_NUMBER: | 13756 case VAR_NUMBER: |
13879 * Make a copy of an item. | 13795 * Make a copy of an item. |
13880 * Lists and Dictionaries are also copied. A deep copy if "deep" is set. | 13796 * Lists and Dictionaries are also copied. A deep copy if "deep" is set. |
13881 */ | 13797 */ |
13882 static void | 13798 static void |
13883 item_copy(from, to, deep) | 13799 item_copy(from, to, deep) |
13884 typeval *from; | 13800 typval_T *from; |
13885 typeval *to; | 13801 typval_T *to; |
13886 int deep; | 13802 int deep; |
13887 { | 13803 { |
13888 static int recurse = 0; | 13804 static int recurse = 0; |
13889 | 13805 |
13890 if (recurse >= VAR_MAXNEST) | 13806 if (recurse >= DICT_MAXNEST) |
13891 { | 13807 { |
13892 EMSG(_("E698: variable nested too deep for making a copy")); | 13808 EMSG(_("E698: variable nested too deep for making a copy")); |
13893 return; | 13809 return; |
13894 } | 13810 } |
13895 ++recurse; | 13811 ++recurse; |
13923 void | 13839 void |
13924 ex_echo(eap) | 13840 ex_echo(eap) |
13925 exarg_T *eap; | 13841 exarg_T *eap; |
13926 { | 13842 { |
13927 char_u *arg = eap->arg; | 13843 char_u *arg = eap->arg; |
13928 typeval rettv; | 13844 typval_T rettv; |
13929 char_u *tofree; | 13845 char_u *tofree; |
13930 char_u *p; | 13846 char_u *p; |
13931 int needclr = TRUE; | 13847 int needclr = TRUE; |
13932 int atstart = TRUE; | 13848 int atstart = TRUE; |
13933 char_u numbuf[NUMBUFLEN]; | 13849 char_u numbuf[NUMBUFLEN]; |
14031 void | 13947 void |
14032 ex_execute(eap) | 13948 ex_execute(eap) |
14033 exarg_T *eap; | 13949 exarg_T *eap; |
14034 { | 13950 { |
14035 char_u *arg = eap->arg; | 13951 char_u *arg = eap->arg; |
14036 typeval rettv; | 13952 typval_T rettv; |
14037 int ret = OK; | 13953 int ret = OK; |
14038 char_u *p; | 13954 char_u *p; |
14039 garray_T ga; | 13955 garray_T ga; |
14040 int len; | 13956 int len; |
14041 int save_did_emsg; | 13957 int save_did_emsg; |
14165 int flags = 0; | 14081 int flags = 0; |
14166 ufunc_T *fp; | 14082 ufunc_T *fp; |
14167 int indent; | 14083 int indent; |
14168 int nesting; | 14084 int nesting; |
14169 char_u *skip_until = NULL; | 14085 char_u *skip_until = NULL; |
14170 VAR v; | 14086 dictitem_T *v; |
14171 funcdict fudi; | 14087 funcdict_T fudi; |
14172 static int func_nr = 0; /* number for nameless function */ | 14088 static int func_nr = 0; /* number for nameless function */ |
14173 int paren; | 14089 int paren; |
14174 | 14090 |
14175 /* | 14091 /* |
14176 * ":function" without argument: list functions. | 14092 * ":function" without argument: list functions. |
14498 * If there are no errors, add the function | 14414 * If there are no errors, add the function |
14499 */ | 14415 */ |
14500 if (fudi.fd_dict == NULL) | 14416 if (fudi.fd_dict == NULL) |
14501 { | 14417 { |
14502 v = find_var(name, NULL); | 14418 v = find_var(name, NULL); |
14503 if (v != NULL && v->tv.v_type == VAR_FUNC) | 14419 if (v != NULL && v->di_tv.v_type == VAR_FUNC) |
14504 { | 14420 { |
14505 EMSG2(_("E707: Function name conflicts with variable: %s"), name); | 14421 EMSG2(_("E707: Function name conflicts with variable: %s"), name); |
14506 goto erret; | 14422 goto erret; |
14507 } | 14423 } |
14508 | 14424 |
14614 static char_u * | 14530 static char_u * |
14615 trans_function_name(pp, skip, flags, fdp) | 14531 trans_function_name(pp, skip, flags, fdp) |
14616 char_u **pp; | 14532 char_u **pp; |
14617 int skip; /* only find the end, don't evaluate */ | 14533 int skip; /* only find the end, don't evaluate */ |
14618 int flags; | 14534 int flags; |
14619 funcdict *fdp; /* return: info about dictionary used */ | 14535 funcdict_T *fdp; /* return: info about dictionary used */ |
14620 { | 14536 { |
14621 char_u *name = NULL; | 14537 char_u *name = NULL; |
14622 char_u *start; | 14538 char_u *start; |
14623 char_u *end; | 14539 char_u *end; |
14624 int lead; | 14540 int lead; |
14625 char_u sid_buf[20]; | 14541 char_u sid_buf[20]; |
14626 int len; | 14542 int len; |
14627 lval lv; | 14543 lval_T lv; |
14628 | 14544 |
14629 if (fdp != NULL) | 14545 if (fdp != NULL) |
14630 vim_memset(fdp, 0, sizeof(funcdict)); | 14546 vim_memset(fdp, 0, sizeof(funcdict_T)); |
14631 start = *pp; | 14547 start = *pp; |
14632 | 14548 |
14633 /* Check for hard coded <SNR>: already translated function ID (from a user | 14549 /* Check for hard coded <SNR>: already translated function ID (from a user |
14634 * command). */ | 14550 * command). */ |
14635 if ((*pp)[0] == K_SPECIAL && (*pp)[1] == KS_EXTRA | 14551 if ((*pp)[0] == K_SPECIAL && (*pp)[1] == KS_EXTRA |
14926 exarg_T *eap; | 14842 exarg_T *eap; |
14927 { | 14843 { |
14928 ufunc_T *fp = NULL; | 14844 ufunc_T *fp = NULL; |
14929 char_u *p; | 14845 char_u *p; |
14930 char_u *name; | 14846 char_u *name; |
14931 funcdict fudi; | 14847 funcdict_T fudi; |
14932 | 14848 |
14933 p = eap->arg; | 14849 p = eap->arg; |
14934 name = trans_function_name(&p, eap->skip, 0, &fudi); | 14850 name = trans_function_name(&p, eap->skip, 0, &fudi); |
14935 vim_free(fudi.fd_newkey); | 14851 vim_free(fudi.fd_newkey); |
14936 if (name == NULL) | 14852 if (name == NULL) |
15055 */ | 14971 */ |
15056 static void | 14972 static void |
15057 call_user_func(fp, argcount, argvars, rettv, firstline, lastline, selfdict) | 14973 call_user_func(fp, argcount, argvars, rettv, firstline, lastline, selfdict) |
15058 ufunc_T *fp; /* pointer to function */ | 14974 ufunc_T *fp; /* pointer to function */ |
15059 int argcount; /* nr of args */ | 14975 int argcount; /* nr of args */ |
15060 typeval *argvars; /* arguments */ | 14976 typval_T *argvars; /* arguments */ |
15061 typeval *rettv; /* return value */ | 14977 typval_T *rettv; /* return value */ |
15062 linenr_T firstline; /* first line of range */ | 14978 linenr_T firstline; /* first line of range */ |
15063 linenr_T lastline; /* last line of range */ | 14979 linenr_T lastline; /* last line of range */ |
15064 dictvar *selfdict; /* Dictionary for "self" */ | 14980 dict_T *selfdict; /* Dictionary for "self" */ |
15065 { | 14981 { |
15066 char_u *save_sourcing_name; | 14982 char_u *save_sourcing_name; |
15067 linenr_T save_sourcing_lnum; | 14983 linenr_T save_sourcing_lnum; |
15068 scid_T save_current_SID; | 14984 scid_T save_current_SID; |
15069 struct funccall fc; | 14985 funccall_T fc; |
15070 struct funccall *save_fcp = current_funccal; | 14986 funccall_T *save_fcp = current_funccal; |
15071 int save_did_emsg; | 14987 int save_did_emsg; |
15072 static int depth = 0; | 14988 static int depth = 0; |
14989 dictitem_T *v; | |
14990 int fixvar_idx = 0; /* index in fixvar[] */ | |
14991 int i; | |
14992 int ai; | |
14993 char_u numbuf[NUMBUFLEN]; | |
14994 char_u *name; | |
15073 | 14995 |
15074 /* If depth of calling is getting too high, don't execute the function */ | 14996 /* If depth of calling is getting too high, don't execute the function */ |
15075 if (depth >= p_mfd) | 14997 if (depth >= p_mfd) |
15076 { | 14998 { |
15077 EMSG(_("E132: Function call depth is higher than 'maxfuncdepth'")); | 14999 EMSG(_("E132: Function call depth is higher than 'maxfuncdepth'")); |
15081 } | 15003 } |
15082 ++depth; | 15004 ++depth; |
15083 | 15005 |
15084 line_breakcheck(); /* check for CTRL-C hit */ | 15006 line_breakcheck(); /* check for CTRL-C hit */ |
15085 | 15007 |
15086 /* set local variables */ | 15008 current_funccal = &fc; |
15087 vars_init(&fc.l_vars); | |
15088 fc.func = fp; | 15009 fc.func = fp; |
15089 fc.argcount = argcount; | |
15090 fc.argvars = argvars; | |
15091 fc.rettv = rettv; | 15010 fc.rettv = rettv; |
15092 rettv->vval.v_number = 0; | 15011 rettv->vval.v_number = 0; |
15093 fc.linenr = 0; | 15012 fc.linenr = 0; |
15094 fc.returned = FALSE; | 15013 fc.returned = FALSE; |
15095 fc.level = ex_nesting_level; | 15014 fc.level = ex_nesting_level; |
15096 fc.a0_var.tv.v_type = VAR_NUMBER; | |
15097 fc.a0_var.tv.vval.v_number = argcount - fp->args.ga_len; | |
15098 fc.a0_var.v_name[0] = NUL; | |
15099 current_funccal = &fc; | |
15100 fc.firstline.tv.v_type = VAR_NUMBER; | |
15101 fc.firstline.tv.vval.v_number = firstline; | |
15102 fc.firstline.v_name[0] = NUL; | |
15103 fc.lastline.tv.v_type = VAR_NUMBER; | |
15104 fc.lastline.tv.vval.v_number = lastline; | |
15105 fc.lastline.v_name[0] = NUL; | |
15106 /* Check if this function has a breakpoint. */ | 15015 /* Check if this function has a breakpoint. */ |
15107 fc.breakpoint = dbg_find_breakpoint(FALSE, fp->name, (linenr_T)0); | 15016 fc.breakpoint = dbg_find_breakpoint(FALSE, fp->name, (linenr_T)0); |
15108 fc.dbg_tick = debug_tick; | 15017 fc.dbg_tick = debug_tick; |
15109 | 15018 |
15019 /* | |
15020 * Note about using fc.fixvar[]: This is an array of FIXVAR_CNT variables | |
15021 * with names up to VAR_SHORT_LEN long. This avoids having to alloc/free | |
15022 * each argument variable and saves a lot of time. | |
15023 */ | |
15024 /* | |
15025 * Init l: variables. | |
15026 */ | |
15027 init_var_dict(&fc.l_vars, &fc.l_vars_var); | |
15110 if (selfdict != NULL) | 15028 if (selfdict != NULL) |
15111 { | 15029 { |
15112 VAR v = (VAR)alloc((unsigned)(sizeof(var) + 4)); | 15030 /* Set l:self to "selfdict". */ |
15113 | 15031 v = &fc.fixvar[fixvar_idx++].var; |
15114 if (v != NULL) | 15032 STRCPY(v->di_key, "self"); |
15115 { | 15033 v->di_flags = DI_FLAGS_RO + DI_FLAGS_FIX; |
15116 STRCPY(v->v_name, "self"); | 15034 hash_add(&fc.l_vars.dv_hashtab, DI2HIKEY(v)); |
15117 hash_add(&fc.l_vars, VAR2HIKEY(v)); | 15035 v->di_tv.v_type = VAR_DICT; |
15118 v->tv.v_type = VAR_DICT; | 15036 v->di_tv.vval.v_dict = selfdict; |
15119 v->tv.vval.v_dict = selfdict; | 15037 ++selfdict->dv_refcount; |
15120 ++selfdict->dv_refcount; | 15038 } |
15039 | |
15040 /* | |
15041 * Init a: variables. | |
15042 * Set a:0 to "argcount". | |
15043 * Set a:000 to a list with room for the "..." arguments. | |
15044 */ | |
15045 init_var_dict(&fc.l_avars, &fc.l_avars_var); | |
15046 add_nr_var(&fc.l_avars, &fc.fixvar[fixvar_idx++].var, "0", | |
15047 (varnumber_T)(argcount - fp->args.ga_len)); | |
15048 v = &fc.fixvar[fixvar_idx++].var; | |
15049 STRCPY(v->di_key, "000"); | |
15050 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; | |
15051 hash_add(&fc.l_avars.dv_hashtab, DI2HIKEY(v)); | |
15052 v->di_tv.v_type = VAR_LIST; | |
15053 v->di_tv.vval.v_list = &fc.l_varlist; | |
15054 vim_memset(&fc.l_varlist, 0, sizeof(list_T)); | |
15055 fc.l_varlist.lv_refcount = 99999; | |
15056 | |
15057 /* | |
15058 * Set a:firstline to "firstline" and a:lastline to "lastline". | |
15059 * Set a:name to named arguments. | |
15060 * Set a:N to the "..." arguments. | |
15061 */ | |
15062 add_nr_var(&fc.l_avars, &fc.fixvar[fixvar_idx++].var, "firstline", | |
15063 (varnumber_T)firstline); | |
15064 add_nr_var(&fc.l_avars, &fc.fixvar[fixvar_idx++].var, "lastline", | |
15065 (varnumber_T)lastline); | |
15066 for (i = 0; i < argcount; ++i) | |
15067 { | |
15068 ai = i - fp->args.ga_len; | |
15069 if (ai < 0) | |
15070 /* named argument a:name */ | |
15071 name = FUNCARG(fp, i); | |
15072 else | |
15073 { | |
15074 /* "..." argument a:1, a:2, etc. */ | |
15075 sprintf((char *)numbuf, "%d", ai + 1); | |
15076 name = numbuf; | |
15077 } | |
15078 if (fixvar_idx < FIXVAR_CNT && STRLEN(name) <= VAR_SHORT_LEN) | |
15079 { | |
15080 v = &fc.fixvar[fixvar_idx++].var; | |
15081 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; | |
15082 } | |
15083 else | |
15084 { | |
15085 v = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T) + STRLEN(name))); | |
15086 if (v == NULL) | |
15087 break; | |
15088 v->di_flags = DI_FLAGS_RO; | |
15089 } | |
15090 STRCPY(v->di_key, name); | |
15091 hash_add(&fc.l_avars.dv_hashtab, DI2HIKEY(v)); | |
15092 | |
15093 /* Note: the values are copied directly to avoid alloc/free. */ | |
15094 v->di_tv = argvars[i]; | |
15095 | |
15096 if (ai >= 0 && ai < MAX_FUNC_ARGS) | |
15097 { | |
15098 list_append(&fc.l_varlist, &fc.l_listitems[ai]); | |
15099 fc.l_listitems[ai].li_tv = argvars[i]; | |
15121 } | 15100 } |
15122 } | 15101 } |
15123 | 15102 |
15124 /* Don't redraw while executing the function. */ | 15103 /* Don't redraw while executing the function. */ |
15125 ++RedrawingDisabled; | 15104 ++RedrawingDisabled; |
15142 ++no_wait_return; | 15121 ++no_wait_return; |
15143 msg_scroll = TRUE; /* always scroll up, don't overwrite */ | 15122 msg_scroll = TRUE; /* always scroll up, don't overwrite */ |
15144 msg_str((char_u *)_("calling %s"), sourcing_name); | 15123 msg_str((char_u *)_("calling %s"), sourcing_name); |
15145 if (p_verbose >= 14) | 15124 if (p_verbose >= 14) |
15146 { | 15125 { |
15147 int i; | |
15148 char_u buf[MSG_BUF_LEN]; | 15126 char_u buf[MSG_BUF_LEN]; |
15149 | 15127 |
15150 msg_puts((char_u *)"("); | 15128 msg_puts((char_u *)"("); |
15151 for (i = 0; i < argcount; ++i) | 15129 for (i = 0; i < argcount; ++i) |
15152 { | 15130 { |
15235 } | 15213 } |
15236 | 15214 |
15237 did_emsg |= save_did_emsg; | 15215 did_emsg |= save_did_emsg; |
15238 current_funccal = save_fcp; | 15216 current_funccal = save_fcp; |
15239 | 15217 |
15240 vars_clear(&fc.l_vars); /* free all local variables */ | 15218 /* The a: variables typevals were not alloced, only free the allocated |
15219 * variables. */ | |
15220 vars_clear_ext(&fc.l_avars.dv_hashtab, FALSE); | |
15221 | |
15222 vars_clear(&fc.l_vars.dv_hashtab); /* free all l: variables */ | |
15241 --depth; | 15223 --depth; |
15224 } | |
15225 | |
15226 /* | |
15227 * Add a number variable "name" to dict "dp" with value "nr". | |
15228 */ | |
15229 static void | |
15230 add_nr_var(dp, v, name, nr) | |
15231 dict_T *dp; | |
15232 dictitem_T *v; | |
15233 char *name; | |
15234 varnumber_T nr; | |
15235 { | |
15236 STRCPY(v->di_key, name); | |
15237 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; | |
15238 hash_add(&dp->dv_hashtab, DI2HIKEY(v)); | |
15239 v->di_tv.v_type = VAR_NUMBER; | |
15240 v->di_tv.vval.v_number = nr; | |
15242 } | 15241 } |
15243 | 15242 |
15244 /* | 15243 /* |
15245 * ":return [expr]" | 15244 * ":return [expr]" |
15246 */ | 15245 */ |
15247 void | 15246 void |
15248 ex_return(eap) | 15247 ex_return(eap) |
15249 exarg_T *eap; | 15248 exarg_T *eap; |
15250 { | 15249 { |
15251 char_u *arg = eap->arg; | 15250 char_u *arg = eap->arg; |
15252 typeval rettv; | 15251 typval_T rettv; |
15253 int returning = FALSE; | 15252 int returning = FALSE; |
15254 | 15253 |
15255 if (current_funccal == NULL) | 15254 if (current_funccal == NULL) |
15256 { | 15255 { |
15257 EMSG(_("E133: :return not inside a function")); | 15256 EMSG(_("E133: :return not inside a function")); |
15295 | 15294 |
15296 /* | 15295 /* |
15297 * Return from a function. Possibly makes the return pending. Also called | 15296 * Return from a function. Possibly makes the return pending. Also called |
15298 * for a pending return at the ":endtry" or after returning from an extra | 15297 * for a pending return at the ":endtry" or after returning from an extra |
15299 * do_cmdline(). "reanimate" is used in the latter case. "is_cmd" is set | 15298 * do_cmdline(). "reanimate" is used in the latter case. "is_cmd" is set |
15300 * when called due to a ":return" command. "rettv" may point to a typeval | 15299 * when called due to a ":return" command. "rettv" may point to a typval_T |
15301 * with the return rettv. Returns TRUE when the return can be carried out, | 15300 * with the return rettv. Returns TRUE when the return can be carried out, |
15302 * FALSE when the return gets pending. | 15301 * FALSE when the return gets pending. |
15303 */ | 15302 */ |
15304 int | 15303 int |
15305 do_return(eap, reanimate, is_cmd, rettv) | 15304 do_return(eap, reanimate, is_cmd, rettv) |
15340 | 15339 |
15341 if (rettv != NULL) | 15340 if (rettv != NULL) |
15342 { | 15341 { |
15343 /* Store the value of the pending return. */ | 15342 /* Store the value of the pending return. */ |
15344 if ((cstack->cs_rettv[idx] = alloc_tv()) != NULL) | 15343 if ((cstack->cs_rettv[idx] = alloc_tv()) != NULL) |
15345 *(typeval *)cstack->cs_rettv[idx] = *(typeval *)rettv; | 15344 *(typval_T *)cstack->cs_rettv[idx] = *(typval_T *)rettv; |
15346 else | 15345 else |
15347 EMSG(_(e_outofmem)); | 15346 EMSG(_(e_outofmem)); |
15348 } | 15347 } |
15349 else | 15348 else |
15350 cstack->cs_rettv[idx] = NULL; | 15349 cstack->cs_rettv[idx] = NULL; |
15368 * a return immediately after reanimation, the value is already | 15367 * a return immediately after reanimation, the value is already |
15369 * there. */ | 15368 * there. */ |
15370 if (!reanimate && rettv != NULL) | 15369 if (!reanimate && rettv != NULL) |
15371 { | 15370 { |
15372 clear_tv(current_funccal->rettv); | 15371 clear_tv(current_funccal->rettv); |
15373 *current_funccal->rettv = *(typeval *)rettv; | 15372 *current_funccal->rettv = *(typval_T *)rettv; |
15374 if (!is_cmd) | 15373 if (!is_cmd) |
15375 vim_free(rettv); | 15374 vim_free(rettv); |
15376 } | 15375 } |
15377 } | 15376 } |
15378 | 15377 |
15384 */ | 15383 */ |
15385 void | 15384 void |
15386 discard_pending_return(rettv) | 15385 discard_pending_return(rettv) |
15387 void *rettv; | 15386 void *rettv; |
15388 { | 15387 { |
15389 free_tv((typeval *)rettv); | 15388 free_tv((typval_T *)rettv); |
15390 } | 15389 } |
15391 | 15390 |
15392 /* | 15391 /* |
15393 * Generate a return command for producing the value of "rettv". The result | 15392 * Generate a return command for producing the value of "rettv". The result |
15394 * is an allocated string. Used by report_pending() for verbose messages. | 15393 * is an allocated string. Used by report_pending() for verbose messages. |
15402 char_u numbuf[NUMBUFLEN]; | 15401 char_u numbuf[NUMBUFLEN]; |
15403 | 15402 |
15404 if (rettv == NULL) | 15403 if (rettv == NULL) |
15405 s = (char_u *)""; | 15404 s = (char_u *)""; |
15406 else | 15405 else |
15407 s = echo_string((typeval *)rettv, &tofree, numbuf); | 15406 s = echo_string((typval_T *)rettv, &tofree, numbuf); |
15408 | 15407 |
15409 STRCPY(IObuff, ":return "); | 15408 STRCPY(IObuff, ":return "); |
15410 STRNCPY(IObuff + 8, s, IOSIZE - 8); | 15409 STRNCPY(IObuff + 8, s, IOSIZE - 8); |
15411 if (STRLEN(s) + 8 >= IOSIZE) | 15410 if (STRLEN(s) + 8 >= IOSIZE) |
15412 STRCPY(IObuff + IOSIZE - 4, "..."); | 15411 STRCPY(IObuff + IOSIZE - 4, "..."); |
15424 get_func_line(c, cookie, indent) | 15423 get_func_line(c, cookie, indent) |
15425 int c; /* not used */ | 15424 int c; /* not used */ |
15426 void *cookie; | 15425 void *cookie; |
15427 int indent; /* not used */ | 15426 int indent; /* not used */ |
15428 { | 15427 { |
15429 struct funccall *fcp = (struct funccall *)cookie; | 15428 funccall_T *fcp = (funccall_T *)cookie; |
15430 char_u *retval; | 15429 char_u *retval; |
15431 garray_T *gap; /* growarray with function lines */ | 15430 garray_T *gap; /* growarray with function lines */ |
15432 | 15431 |
15433 /* If breakpoints have been added/deleted need to check for it. */ | 15432 /* If breakpoints have been added/deleted need to check for it. */ |
15434 if (fcp->dbg_tick != debug_tick) | 15433 if (fcp->dbg_tick != debug_tick) |
15468 */ | 15467 */ |
15469 int | 15468 int |
15470 func_has_ended(cookie) | 15469 func_has_ended(cookie) |
15471 void *cookie; | 15470 void *cookie; |
15472 { | 15471 { |
15473 struct funccall *fcp = (struct funccall *)cookie; | 15472 funccall_T *fcp = (funccall_T *)cookie; |
15474 | 15473 |
15475 /* Ignore the "abort" flag if the abortion behavior has been changed due to | 15474 /* Ignore the "abort" flag if the abortion behavior has been changed due to |
15476 * an error inside a try conditional. */ | 15475 * an error inside a try conditional. */ |
15477 return (((fcp->func->flags & FC_ABORT) && did_emsg && !aborted_in_try()) | 15476 return (((fcp->func->flags & FC_ABORT) && did_emsg && !aborted_in_try()) |
15478 || fcp->returned); | 15477 || fcp->returned); |
15483 */ | 15482 */ |
15484 int | 15483 int |
15485 func_has_abort(cookie) | 15484 func_has_abort(cookie) |
15486 void *cookie; | 15485 void *cookie; |
15487 { | 15486 { |
15488 return ((struct funccall *)cookie)->func->flags & FC_ABORT; | 15487 return ((funccall_T *)cookie)->func->flags & FC_ABORT; |
15489 } | 15488 } |
15490 | 15489 |
15491 #if defined(FEAT_VIMINFO) || defined(FEAT_SESSION) | 15490 #if defined(FEAT_VIMINFO) || defined(FEAT_SESSION) |
15492 typedef enum | 15491 typedef enum |
15493 { | 15492 { |
15525 vir_T *virp; | 15524 vir_T *virp; |
15526 int writing; | 15525 int writing; |
15527 { | 15526 { |
15528 char_u *tab; | 15527 char_u *tab; |
15529 int is_string = FALSE; | 15528 int is_string = FALSE; |
15530 typeval tv; | 15529 typval_T tv; |
15531 | 15530 |
15532 if (!writing && (find_viminfo_parameter('!') != NULL)) | 15531 if (!writing && (find_viminfo_parameter('!') != NULL)) |
15533 { | 15532 { |
15534 tab = vim_strchr(virp->vir_line + 1, '\t'); | 15533 tab = vim_strchr(virp->vir_line + 1, '\t'); |
15535 if (tab != NULL) | 15534 if (tab != NULL) |
15567 */ | 15566 */ |
15568 void | 15567 void |
15569 write_viminfo_varlist(fp) | 15568 write_viminfo_varlist(fp) |
15570 FILE *fp; | 15569 FILE *fp; |
15571 { | 15570 { |
15572 hashitem *hi; | 15571 hashitem_T *hi; |
15573 VAR this_var; | 15572 dictitem_T *this_var; |
15574 int todo; | 15573 int todo; |
15575 char *s; | 15574 char *s; |
15576 char_u *tofree; | 15575 char_u *tofree; |
15577 char_u numbuf[NUMBUFLEN]; | 15576 char_u numbuf[NUMBUFLEN]; |
15578 | 15577 |
15579 if (find_viminfo_parameter('!') == NULL) | 15578 if (find_viminfo_parameter('!') == NULL) |
15580 return; | 15579 return; |
15581 | 15580 |
15582 fprintf(fp, _("\n# global variables:\n")); | 15581 fprintf(fp, _("\n# global variables:\n")); |
15583 | 15582 |
15584 todo = variables.ht_used; | 15583 todo = globvarht.ht_used; |
15585 for (hi = variables.ht_array; todo > 0; ++hi) | 15584 for (hi = globvarht.ht_array; todo > 0; ++hi) |
15586 { | 15585 { |
15587 if (!HASHITEM_EMPTY(hi)) | 15586 if (!HASHITEM_EMPTY(hi)) |
15588 { | 15587 { |
15589 --todo; | 15588 --todo; |
15590 this_var = HI2VAR(hi); | 15589 this_var = HI2DI(hi); |
15591 if (var_flavour(this_var->v_name) == VAR_FLAVOUR_VIMINFO) | 15590 if (var_flavour(this_var->di_key) == VAR_FLAVOUR_VIMINFO) |
15592 { | 15591 { |
15593 switch (this_var->tv.v_type) | 15592 switch (this_var->di_tv.v_type) |
15594 { | 15593 { |
15595 case VAR_STRING: s = "STR"; break; | 15594 case VAR_STRING: s = "STR"; break; |
15596 case VAR_NUMBER: s = "NUM"; break; | 15595 case VAR_NUMBER: s = "NUM"; break; |
15597 default: continue; | 15596 default: continue; |
15598 } | 15597 } |
15599 fprintf(fp, "!%s\t%s\t", this_var->v_name, s); | 15598 fprintf(fp, "!%s\t%s\t", this_var->di_key, s); |
15600 viminfo_writestring(fp, echo_string(&this_var->tv, | 15599 viminfo_writestring(fp, echo_string(&this_var->di_tv, |
15601 &tofree, numbuf)); | 15600 &tofree, numbuf)); |
15602 vim_free(tofree); | 15601 vim_free(tofree); |
15603 } | 15602 } |
15604 } | 15603 } |
15605 } | 15604 } |
15609 #if defined(FEAT_SESSION) || defined(PROTO) | 15608 #if defined(FEAT_SESSION) || defined(PROTO) |
15610 int | 15609 int |
15611 store_session_globals(fd) | 15610 store_session_globals(fd) |
15612 FILE *fd; | 15611 FILE *fd; |
15613 { | 15612 { |
15614 hashitem *hi; | 15613 hashitem_T *hi; |
15615 VAR this_var; | 15614 dictitem_T *this_var; |
15616 int todo; | 15615 int todo; |
15617 char_u *p, *t; | 15616 char_u *p, *t; |
15618 | 15617 |
15619 todo = variables.ht_used; | 15618 todo = globvarht.ht_used; |
15620 for (hi = variables.ht_array; todo > 0; ++hi) | 15619 for (hi = globvarht.ht_array; todo > 0; ++hi) |
15621 { | 15620 { |
15622 if (!HASHITEM_EMPTY(hi)) | 15621 if (!HASHITEM_EMPTY(hi)) |
15623 { | 15622 { |
15624 --todo; | 15623 --todo; |
15625 this_var = HI2VAR(hi); | 15624 this_var = HI2DI(hi); |
15626 if ((this_var->tv.v_type == VAR_NUMBER | 15625 if ((this_var->di_tv.v_type == VAR_NUMBER |
15627 || this_var->tv.v_type == VAR_STRING) | 15626 || this_var->di_tv.v_type == VAR_STRING) |
15628 && var_flavour(this_var->v_name) == VAR_FLAVOUR_SESSION) | 15627 && var_flavour(this_var->di_key) == VAR_FLAVOUR_SESSION) |
15629 { | 15628 { |
15630 /* Escape special characters with a backslash. Turn a LF and | 15629 /* Escape special characters with a backslash. Turn a LF and |
15631 * CR into \n and \r. */ | 15630 * CR into \n and \r. */ |
15632 p = vim_strsave_escaped(get_tv_string(&this_var->tv), | 15631 p = vim_strsave_escaped(get_tv_string(&this_var->di_tv), |
15633 (char_u *)"\\\"\n\r"); | 15632 (char_u *)"\\\"\n\r"); |
15634 if (p == NULL) /* out of memory */ | 15633 if (p == NULL) /* out of memory */ |
15635 break; | 15634 break; |
15636 for (t = p; *t != NUL; ++t) | 15635 for (t = p; *t != NUL; ++t) |
15637 if (*t == '\n') | 15636 if (*t == '\n') |
15638 *t = 'n'; | 15637 *t = 'n'; |
15639 else if (*t == '\r') | 15638 else if (*t == '\r') |
15640 *t = 'r'; | 15639 *t = 'r'; |
15641 if ((fprintf(fd, "let %s = %c%s%c", | 15640 if ((fprintf(fd, "let %s = %c%s%c", |
15642 this_var->v_name, | 15641 this_var->di_key, |
15643 (this_var->tv.v_type == VAR_STRING) ? '"' : ' ', | 15642 (this_var->di_tv.v_type == VAR_STRING) ? '"' |
15644 p, | 15643 : ' ', |
15645 (this_var->tv.v_type == VAR_STRING) ? '"' : ' ') < 0) | 15644 p, |
15645 (this_var->di_tv.v_type == VAR_STRING) ? '"' | |
15646 : ' ') < 0) | |
15646 || put_eol(fd) == FAIL) | 15647 || put_eol(fd) == FAIL) |
15647 { | 15648 { |
15648 vim_free(p); | 15649 vim_free(p); |
15649 return FAIL; | 15650 return FAIL; |
15650 } | 15651 } |