To: vim_dev@googlegroups.com Subject: Patch 8.1.1933 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.1933 Problem: The eval.c file is too big. Solution: Move code related to variables to evalvars.c. (Yegappan Lakshmanan, closes #4868) Files: Filelist, src/Make_cyg_ming.mak, src/Make_morph.mak, src/Make_mvc.mak, src/Make_vms.mms, src/Makefile, src/README.md, src/eval.c, src/evalfunc.c, src/evalvars.c, src/globals.h, src/proto.h, src/proto/eval.pro, src/proto/evalvars.pro, src/vim.h *** ../vim-8.1.1932/Filelist 2019-08-25 15:40:39.658739525 +0200 --- Filelist 2019-08-27 22:37:44.273253741 +0200 *************** *** 35,40 **** --- 35,41 ---- src/edit.c \ src/eval.c \ src/evalfunc.c \ + src/evalvars.c \ src/ex_cmdidxs.h \ src/ex_cmds.c \ src/ex_cmds.h \ *************** *** 188,193 **** --- 189,195 ---- src/proto/edit.pro \ src/proto/eval.pro \ src/proto/evalfunc.pro \ + src/proto/evalvars.pro \ src/proto/ex_cmds.pro \ src/proto/ex_cmds2.pro \ src/proto/ex_docmd.pro \ *** ../vim-8.1.1932/src/Make_cyg_ming.mak 2019-08-25 15:40:39.658739525 +0200 --- src/Make_cyg_ming.mak 2019-08-27 22:37:44.273253741 +0200 *************** *** 722,727 **** --- 722,728 ---- $(OUTDIR)/edit.o \ $(OUTDIR)/eval.o \ $(OUTDIR)/evalfunc.o \ + $(OUTDIR)/evalvars.o \ $(OUTDIR)/ex_cmds.o \ $(OUTDIR)/ex_cmds2.o \ $(OUTDIR)/ex_docmd.o \ *** ../vim-8.1.1932/src/Make_morph.mak 2019-08-25 15:40:39.658739525 +0200 --- src/Make_morph.mak 2019-08-27 22:37:44.273253741 +0200 *************** *** 42,47 **** --- 42,48 ---- edit.c \ eval.c \ evalfunc.c \ + evalvars.c \ ex_cmds.c \ ex_cmds2.c \ ex_docmd.c \ *** ../vim-8.1.1932/src/Make_mvc.mak 2019-08-25 15:40:39.658739525 +0200 --- src/Make_mvc.mak 2019-08-27 22:37:44.273253741 +0200 *************** *** 731,736 **** --- 731,737 ---- $(OUTDIR)\edit.obj \ $(OUTDIR)\eval.obj \ $(OUTDIR)\evalfunc.obj \ + $(OUTDIR)\evalvars.obj \ $(OUTDIR)\ex_cmds.obj \ $(OUTDIR)\ex_cmds2.obj \ $(OUTDIR)\ex_docmd.obj \ *************** *** 1486,1491 **** --- 1487,1494 ---- $(OUTDIR)/evalfunc.obj: $(OUTDIR) evalfunc.c $(INCL) + $(OUTDIR)/evalvars.obj: $(OUTDIR) evalvars.c $(INCL) + $(OUTDIR)/ex_cmds.obj: $(OUTDIR) ex_cmds.c $(INCL) $(OUTDIR)/ex_cmds2.obj: $(OUTDIR) ex_cmds2.c $(INCL) *************** *** 1771,1776 **** --- 1774,1780 ---- proto/edit.pro \ proto/eval.pro \ proto/evalfunc.pro \ + proto/evalvars.pro \ proto/ex_cmds.pro \ proto/ex_cmds2.pro \ proto/ex_docmd.pro \ *** ../vim-8.1.1932/src/Make_vms.mms 2019-08-25 15:40:39.658739525 +0200 --- src/Make_vms.mms 2019-08-27 22:37:44.273253741 +0200 *************** *** 309,315 **** SRC = arabic.c arglist.c autocmd.c beval.c blob.c blowfish.c buffer.c \ change.c charset.c cmdexpand.c cmdhist.c crypt.c crypt_zip.c \ ! debugger.c dict.c diff.c digraph.c edit.c eval.c evalfunc.c ex_cmds.c \ ex_cmds2.c ex_docmd.c ex_eval.c ex_getln.c if_cscope.c if_xcmdsrv.c \ fileio.c findfile.c fold.c getchar.c hardcopy.c hashtab.c highlight.c \ indent.c insexpand.c json.c list.c main.c map.c mark.c menu.c mbyte.c \ --- 309,316 ---- SRC = arabic.c arglist.c autocmd.c beval.c blob.c blowfish.c buffer.c \ change.c charset.c cmdexpand.c cmdhist.c crypt.c crypt_zip.c \ ! debugger.c dict.c diff.c digraph.c edit.c eval.c evalfunc.c \ ! evalvars.c ex_cmds.c \ ex_cmds2.c ex_docmd.c ex_eval.c ex_getln.c if_cscope.c if_xcmdsrv.c \ fileio.c findfile.c fold.c getchar.c hardcopy.c hashtab.c highlight.c \ indent.c insexpand.c json.c list.c main.c map.c mark.c menu.c mbyte.c \ *************** *** 326,332 **** OBJ = arabic.obj arglist.obj autocmd.obj beval.obj blob.obj blowfish.obj \ buffer.obj change.obj charset.obj cmdexpand.obj cmdhist.obj \ crypt.obj crypt_zip.obj debugger.obj dict.obj diff.obj digraph.obj \ ! edit.obj eval.obj evalfunc.obj ex_cmds.obj ex_cmds2.obj ex_docmd.obj \ ex_eval.obj ex_getln.obj if_cscope.obj if_xcmdsrv.obj fileio.obj \ findfile.obj fold.obj getchar.obj hardcopy.obj hashtab.obj \ highlight.obj indent.obj insexpand.obj json.obj list.obj main.obj \ --- 327,334 ---- OBJ = arabic.obj arglist.obj autocmd.obj beval.obj blob.obj blowfish.obj \ buffer.obj change.obj charset.obj cmdexpand.obj cmdhist.obj \ crypt.obj crypt_zip.obj debugger.obj dict.obj diff.obj digraph.obj \ ! edit.obj eval.obj evalfunc.obj evalvars.obj ex_cmds.obj ex_cmds2.obj \ ! ex_docmd.obj \ ex_eval.obj ex_getln.obj if_cscope.obj if_xcmdsrv.obj fileio.obj \ findfile.obj fold.obj getchar.obj hardcopy.obj hashtab.obj \ highlight.obj indent.obj insexpand.obj json.obj list.obj main.obj \ *************** *** 569,574 **** --- 571,580 ---- ascii.h keymap.h term.h macros.h option.h structs.h \ regexp.h gui.h beval.h [.proto]gui_beval.pro alloc.h ex_cmds.h spell.h \ proto.h globals.h version.h + evalvars.obj : evalvars.c vim.h [.auto]config.h feature.h os_unix.h \ + ascii.h keymap.h term.h macros.h option.h structs.h \ + regexp.h gui.h beval.h [.proto]gui_beval.pro alloc.h ex_cmds.h spell.h \ + proto.h globals.h version.h ex_cmds.obj : ex_cmds.c vim.h [.auto]config.h feature.h os_unix.h \ ascii.h keymap.h term.h macros.h structs.h regexp.h \ gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ *** ../vim-8.1.1932/src/Makefile 2019-08-25 15:40:39.658739525 +0200 --- src/Makefile 2019-08-27 22:37:44.273253741 +0200 *************** *** 1596,1601 **** --- 1596,1602 ---- edit.c \ eval.c \ evalfunc.c \ + evalvars.c \ ex_cmds.c \ ex_cmds2.c \ ex_docmd.c \ *************** *** 1725,1730 **** --- 1726,1732 ---- objects/edit.o \ objects/eval.o \ objects/evalfunc.o \ + objects/evalvars.o \ objects/ex_cmds.o \ objects/ex_cmds2.o \ objects/ex_docmd.o \ *************** *** 1867,1872 **** --- 1869,1875 ---- edit.pro \ eval.pro \ evalfunc.pro \ + evalvars.pro \ ex_cmds.pro \ ex_cmds2.pro \ ex_docmd.pro \ *************** *** 3052,3057 **** --- 3055,3063 ---- objects/evalfunc.o: evalfunc.c $(CCC) -o $@ evalfunc.c + objects/evalvars.o: evalvars.c + $(CCC) -o $@ evalvars.c + objects/ex_cmds.o: ex_cmds.c $(CCC) -o $@ ex_cmds.c *************** *** 3570,3575 **** --- 3576,3585 ---- auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ proto.h globals.h version.h + objects/evalvars.o: evalvars.c vim.h protodef.h auto/config.h feature.h \ + os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ + proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ + proto.h globals.h objects/ex_cmds.o: ex_cmds.c vim.h protodef.h auto/config.h feature.h os_unix.h \ auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ *** ../vim-8.1.1932/src/README.md 2019-08-25 15:40:39.658739525 +0200 --- src/README.md 2019-08-27 22:37:44.273253741 +0200 *************** *** 34,39 **** --- 34,40 ---- diff.c | diff mode (vimdiff) eval.c | expression evaluation evalfunc.c | built-in functions + evalvars.c | vim variables fileio.c | reading and writing files findfile.c | search for files in 'path' fold.c | folding *** ../vim-8.1.1932/src/eval.c 2019-08-23 20:58:42.020375498 +0200 --- src/eval.c 2019-08-27 22:37:44.277253720 +0200 *************** *** 20,34 **** # include #endif - #define DICT_MAXNEST 100 /* maximum nesting of lists and dicts */ - - static char *e_letunexp = N_("E18: Unexpected characters in :let"); - static char *e_undefvar = N_("E121: Undefined variable: %s"); static char *e_missbrac = N_("E111: Missing ']'"); static char *e_dictrange = N_("E719: Cannot use [:] with a Dictionary"); - static char *e_letwrong = N_("E734: Wrong variable type for %s="); - static char *e_illvar = N_("E461: Illegal variable name: %s"); - static char *e_cannot_mod = N_("E995: Cannot modify existing variable"); #ifdef FEAT_FLOAT static char *e_float_as_string = N_("E806: using Float as a String"); #endif --- 20,27 ---- *************** *** 217,241 **** static dictitem_T vimvars_var; /* variable used for v: */ #define vimvarht vimvardict.dv_hashtab - static void ex_let_const(exarg_T *eap, int is_const); - static int ex_let_vars(char_u *arg, typval_T *tv, int copy, int semicolon, int var_count, int is_const, char_u *nextchars); - static char_u *skip_var_list(char_u *arg, int *var_count, int *semicolon); - static char_u *skip_var_one(char_u *arg); - static void list_glob_vars(int *first); - static void list_buf_vars(int *first); - static void list_win_vars(int *first); - static void list_tab_vars(int *first); - static void list_vim_vars(int *first); - static void list_script_vars(int *first); - static char_u *list_arg_vars(exarg_T *eap, char_u *arg, int *first); - static char_u *ex_let_one(char_u *arg, typval_T *tv, int copy, int is_const, char_u *endchars, char_u *op); - static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, int is_const, char_u *op); static int tv_op(typval_T *tv1, typval_T *tv2, char_u *op); - static void ex_unletlock(exarg_T *eap, char_u *argstart, int deep); - static int do_unlet_var(lval_T *lp, char_u *name_end, int forceit); - static int do_lock_var(lval_T *lp, char_u *name_end, int deep, int lock); - static void item_lock(typval_T *tv, int deep, int lock); - static int eval2(char_u **arg, typval_T *rettv, int evaluate); static int eval3(char_u **arg, typval_T *rettv, int evaluate); static int eval4(char_u **arg, typval_T *rettv, int evaluate); --- 210,216 ---- *************** *** 248,265 **** static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate); static int free_unref_items(int copyID); static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate); - static int get_env_len(char_u **arg); - static int get_name_len(char_u **arg, char_u **alias, int evaluate, int verbose); static char_u *make_expanded_name(char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end); - static int get_var_tv(char_u *name, int len, typval_T *rettv, dictitem_T **dip, int verbose, int no_autoload); static void check_vars(char_u *name, int len); static typval_T *alloc_string_tv(char_u *string); - static void delete_var(hashtab_T *ht, hashitem_T *hi); - static void list_one_var(dictitem_T *v, char *prefix, int *first); - static void list_one_var_a(char *prefix, char_u *name, int type, char_u *string, int *first); - static void set_var_const(char_u *name, typval_T *tv, int copy, int is_const); static int tv_check_lock(typval_T *tv, char_u *name, int use_gettext); - static char_u *find_option_end(char_u **arg, int *opt_flags); /* for VIM_VERSION_ defines */ #include "version.h" --- 223,232 ---- *************** *** 267,273 **** /* * Return "n1" divided by "n2", taking care of dividing by zero. */ ! static varnumber_T num_divide(varnumber_T n1, varnumber_T n2) { varnumber_T result; --- 234,240 ---- /* * Return "n1" divided by "n2", taking care of dividing by zero. */ ! varnumber_T num_divide(varnumber_T n1, varnumber_T n2) { varnumber_T result; *************** *** 290,296 **** /* * Return "n1" modulus "n2", taking care of dividing by zero. */ ! static varnumber_T num_modulus(varnumber_T n1, varnumber_T n2) { // Give an error when n2 is 0? --- 257,263 ---- /* * Return "n1" modulus "n2", taking care of dividing by zero. */ ! varnumber_T num_modulus(varnumber_T n1, varnumber_T n2) { // Give an error when n2 is 0? *************** *** 978,983 **** --- 945,982 ---- } /* + * List Vim variables. + */ + void + list_vim_vars(int *first) + { + list_hashtable_vars(&vimvarht, "v:", FALSE, first); + } + + /* + * List script-local variables, if there is a script. + */ + void + list_script_vars(int *first) + { + if (current_sctx.sc_sid > 0 && current_sctx.sc_sid <= ga_scripts.ga_len) + list_hashtable_vars(&SCRIPT_VARS(current_sctx.sc_sid), + "s:", FALSE, first); + } + + int + is_vimvarht(hashtab_T *ht) + { + return ht == &vimvarht; + } + + int + is_compatht(hashtab_T *ht) + { + return ht == &compat_hashtab; + } + + /* * Prepare v: variable "idx" to be used. * Save the current typeval in "save_tv". * When not used yet add the variable to the v: hashtable. *************** *** 1237,2085 **** #endif /* - * Get a list of lines from a HERE document. The here document is a list of - * lines surrounded by a marker. - * cmd << {marker} - * {line1} - * {line2} - * .... - * {marker} - * - * The {marker} is a string. If the optional 'trim' word is supplied before the - * marker, then the leading indentation before the lines (matching the - * indentation in the 'cmd' line) is stripped. - * Returns a List with {lines} or NULL. - */ - static list_T * - heredoc_get(exarg_T *eap, char_u *cmd) - { - char_u *theline; - char_u *marker; - list_T *l; - char_u *p; - int marker_indent_len = 0; - int text_indent_len = 0; - char_u *text_indent = NULL; - - if (eap->getline == NULL) - { - emsg(_("E991: cannot use =<< here")); - return NULL; - } - - // Check for the optional 'trim' word before the marker - cmd = skipwhite(cmd); - if (STRNCMP(cmd, "trim", 4) == 0 && (cmd[4] == NUL || VIM_ISWHITE(cmd[4]))) - { - cmd = skipwhite(cmd + 4); - - // Trim the indentation from all the lines in the here document. - // The amount of indentation trimmed is the same as the indentation of - // the first line after the :let command line. To find the end marker - // the indent of the :let command line is trimmed. - p = *eap->cmdlinep; - while (VIM_ISWHITE(*p)) - { - p++; - marker_indent_len++; - } - text_indent_len = -1; - } - - // The marker is the next word. - if (*cmd != NUL && *cmd != '"') - { - marker = skipwhite(cmd); - p = skiptowhite(marker); - if (*skipwhite(p) != NUL && *skipwhite(p) != '"') - { - emsg(_(e_trailing)); - return NULL; - } - *p = NUL; - if (vim_islower(*marker)) - { - emsg(_("E221: Marker cannot start with lower case letter")); - return NULL; - } - } - else - { - emsg(_("E172: Missing marker")); - return NULL; - } - - l = list_alloc(); - if (l == NULL) - return NULL; - - for (;;) - { - int mi = 0; - int ti = 0; - - theline = eap->getline(NUL, eap->cookie, 0, FALSE); - if (theline == NULL) - { - semsg(_("E990: Missing end marker '%s'"), marker); - break; - } - - // with "trim": skip the indent matching the :let line to find the - // marker - if (marker_indent_len > 0 - && STRNCMP(theline, *eap->cmdlinep, marker_indent_len) == 0) - mi = marker_indent_len; - if (STRCMP(marker, theline + mi) == 0) - { - vim_free(theline); - break; - } - - if (text_indent_len == -1 && *theline != NUL) - { - // set the text indent from the first line. - p = theline; - text_indent_len = 0; - while (VIM_ISWHITE(*p)) - { - p++; - text_indent_len++; - } - text_indent = vim_strnsave(theline, text_indent_len); - } - // with "trim": skip the indent matching the first line - if (text_indent != NULL) - for (ti = 0; ti < text_indent_len; ++ti) - if (theline[ti] != text_indent[ti]) - break; - - if (list_append_string(l, theline + ti, -1) == FAIL) - break; - vim_free(theline); - } - vim_free(text_indent); - - return l; - } - - /* - * ":let" list all variable values - * ":let var1 var2" list variable values - * ":let var = expr" assignment command. - * ":let var += expr" assignment command. - * ":let var -= expr" assignment command. - * ":let var *= expr" assignment command. - * ":let var /= expr" assignment command. - * ":let var %= expr" assignment command. - * ":let var .= expr" assignment command. - * ":let var ..= expr" assignment command. - * ":let [var1, var2] = expr" unpack list. - */ - void - ex_let(exarg_T *eap) - { - ex_let_const(eap, FALSE); - } - - /* - * ":const" list all variable values - * ":const var1 var2" list variable values - * ":const var = expr" assignment command. - * ":const [var1, var2] = expr" unpack list. - */ - void - ex_const(exarg_T *eap) - { - ex_let_const(eap, TRUE); - } - - static void - ex_let_const(exarg_T *eap, int is_const) - { - char_u *arg = eap->arg; - char_u *expr = NULL; - typval_T rettv; - int i; - int var_count = 0; - int semicolon = 0; - char_u op[2]; - char_u *argend; - int first = TRUE; - int concat; - - argend = skip_var_list(arg, &var_count, &semicolon); - if (argend == NULL) - return; - if (argend > arg && argend[-1] == '.') // for var.='str' - --argend; - expr = skipwhite(argend); - concat = expr[0] == '.' - && ((expr[1] == '=' && current_sctx.sc_version < 2) - || (expr[1] == '.' && expr[2] == '=')); - if (*expr != '=' && !((vim_strchr((char_u *)"+-*/%", *expr) != NULL - && expr[1] == '=') || concat)) - { - /* - * ":let" without "=": list variables - */ - if (*arg == '[') - emsg(_(e_invarg)); - else if (expr[0] == '.') - emsg(_("E985: .= is not supported with script version 2")); - else if (!ends_excmd(*arg)) - /* ":let var1 var2" */ - arg = list_arg_vars(eap, arg, &first); - else if (!eap->skip) - { - /* ":let" */ - list_glob_vars(&first); - list_buf_vars(&first); - list_win_vars(&first); - list_tab_vars(&first); - list_script_vars(&first); - list_func_vars(&first); - list_vim_vars(&first); - } - eap->nextcmd = check_nextcmd(arg); - } - else if (expr[0] == '=' && expr[1] == '<' && expr[2] == '<') - { - list_T *l; - - // HERE document - l = heredoc_get(eap, expr + 3); - if (l != NULL) - { - rettv_list_set(&rettv, l); - op[0] = '='; - op[1] = NUL; - (void)ex_let_vars(eap->arg, &rettv, FALSE, semicolon, var_count, - is_const, op); - clear_tv(&rettv); - } - } - else - { - op[0] = '='; - op[1] = NUL; - if (*expr != '=') - { - if (vim_strchr((char_u *)"+-*/%.", *expr) != NULL) - { - op[0] = *expr; // +=, -=, *=, /=, %= or .= - if (expr[0] == '.' && expr[1] == '.') // ..= - ++expr; - } - expr = skipwhite(expr + 2); - } - else - expr = skipwhite(expr + 1); - - if (eap->skip) - ++emsg_skip; - i = eval0(expr, &rettv, &eap->nextcmd, !eap->skip); - if (eap->skip) - { - if (i != FAIL) - clear_tv(&rettv); - --emsg_skip; - } - else if (i != FAIL) - { - (void)ex_let_vars(eap->arg, &rettv, FALSE, semicolon, var_count, - is_const, op); - clear_tv(&rettv); - } - } - } - - /* - * Assign the typevalue "tv" to the variable or variables at "arg_start". - * Handles both "var" with any type and "[var, var; var]" with a list type. - * When "op" is not NULL it points to a string with characters that - * must appear after the variable(s). Use "+", "-" or "." for add, subtract - * or concatenate. - * Returns OK or FAIL; - */ - static int - ex_let_vars( - char_u *arg_start, - typval_T *tv, - int copy, // copy values from "tv", don't move - int semicolon, // from skip_var_list() - int var_count, // from skip_var_list() - int is_const, // lock variables for const - char_u *op) - { - char_u *arg = arg_start; - list_T *l; - int i; - listitem_T *item; - typval_T ltv; - - if (*arg != '[') - { - /* - * ":let var = expr" or ":for var in list" - */ - if (ex_let_one(arg, tv, copy, is_const, op, op) == NULL) - return FAIL; - return OK; - } - - /* - * ":let [v1, v2] = list" or ":for [v1, v2] in listlist" - */ - if (tv->v_type != VAR_LIST || (l = tv->vval.v_list) == NULL) - { - emsg(_(e_listreq)); - return FAIL; - } - - i = list_len(l); - if (semicolon == 0 && var_count < i) - { - emsg(_("E687: Less targets than List items")); - return FAIL; - } - if (var_count - semicolon > i) - { - emsg(_("E688: More targets than List items")); - return FAIL; - } - - item = l->lv_first; - while (*arg != ']') - { - arg = skipwhite(arg + 1); - arg = ex_let_one(arg, &item->li_tv, TRUE, is_const, - (char_u *)",;]", op); - item = item->li_next; - if (arg == NULL) - return FAIL; - - arg = skipwhite(arg); - if (*arg == ';') - { - /* Put the rest of the list (may be empty) in the var after ';'. - * Create a new list for this. */ - l = list_alloc(); - if (l == NULL) - return FAIL; - while (item != NULL) - { - list_append_tv(l, &item->li_tv); - item = item->li_next; - } - - ltv.v_type = VAR_LIST; - ltv.v_lock = 0; - ltv.vval.v_list = l; - l->lv_refcount = 1; - - arg = ex_let_one(skipwhite(arg + 1), <v, FALSE, is_const, - (char_u *)"]", op); - clear_tv(<v); - if (arg == NULL) - return FAIL; - break; - } - else if (*arg != ',' && *arg != ']') - { - internal_error("ex_let_vars()"); - return FAIL; - } - } - - return OK; - } - - /* - * Skip over assignable variable "var" or list of variables "[var, var]". - * Used for ":let varvar = expr" and ":for varvar in expr". - * For "[var, var]" increment "*var_count" for each variable. - * for "[var, var; var]" set "semicolon". - * Return NULL for an error. - */ - static char_u * - skip_var_list( - char_u *arg, - int *var_count, - int *semicolon) - { - char_u *p, *s; - - if (*arg == '[') - { - /* "[var, var]": find the matching ']'. */ - p = arg; - for (;;) - { - p = skipwhite(p + 1); /* skip whites after '[', ';' or ',' */ - s = skip_var_one(p); - if (s == p) - { - semsg(_(e_invarg2), p); - return NULL; - } - ++*var_count; - - p = skipwhite(s); - if (*p == ']') - break; - else if (*p == ';') - { - if (*semicolon == 1) - { - emsg(_("Double ; in list of variables")); - return NULL; - } - *semicolon = 1; - } - else if (*p != ',') - { - semsg(_(e_invarg2), p); - return NULL; - } - } - return p + 1; - } - else - return skip_var_one(arg); - } - - /* - * Skip one (assignable) variable name, including @r, $VAR, &option, d.key, - * l[idx]. - */ - static char_u * - skip_var_one(char_u *arg) - { - if (*arg == '@' && arg[1] != NUL) - return arg + 2; - return find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg, - NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); - } - - /* - * List variables for hashtab "ht" with prefix "prefix". - * If "empty" is TRUE also list NULL strings as empty strings. - */ - void - list_hashtable_vars( - hashtab_T *ht, - char *prefix, - int empty, - int *first) - { - hashitem_T *hi; - dictitem_T *di; - int todo; - char_u buf[IOSIZE]; - - todo = (int)ht->ht_used; - for (hi = ht->ht_array; todo > 0 && !got_int; ++hi) - { - if (!HASHITEM_EMPTY(hi)) - { - --todo; - di = HI2DI(hi); - - // apply :filter /pat/ to variable name - vim_strncpy((char_u *)buf, (char_u *)prefix, IOSIZE - 1); - vim_strcat((char_u *)buf, di->di_key, IOSIZE); - if (message_filtered(buf)) - continue; - - if (empty || di->di_tv.v_type != VAR_STRING - || di->di_tv.vval.v_string != NULL) - list_one_var(di, prefix, first); - } - } - } - - /* - * List global variables. - */ - static void - list_glob_vars(int *first) - { - list_hashtable_vars(&globvarht, "", TRUE, first); - } - - /* - * List buffer variables. - */ - static void - list_buf_vars(int *first) - { - list_hashtable_vars(&curbuf->b_vars->dv_hashtab, "b:", TRUE, first); - } - - /* - * List window variables. - */ - static void - list_win_vars(int *first) - { - list_hashtable_vars(&curwin->w_vars->dv_hashtab, "w:", TRUE, first); - } - - /* - * List tab page variables. - */ - static void - list_tab_vars(int *first) - { - list_hashtable_vars(&curtab->tp_vars->dv_hashtab, "t:", TRUE, first); - } - - /* - * List Vim variables. - */ - static void - list_vim_vars(int *first) - { - list_hashtable_vars(&vimvarht, "v:", FALSE, first); - } - - /* - * List script-local variables, if there is a script. - */ - static void - list_script_vars(int *first) - { - if (current_sctx.sc_sid > 0 && current_sctx.sc_sid <= ga_scripts.ga_len) - list_hashtable_vars(&SCRIPT_VARS(current_sctx.sc_sid), - "s:", FALSE, first); - } - - /* - * List variables in "arg". - */ - static char_u * - list_arg_vars(exarg_T *eap, char_u *arg, int *first) - { - int error = FALSE; - int len; - char_u *name; - char_u *name_start; - char_u *arg_subsc; - char_u *tofree; - typval_T tv; - - while (!ends_excmd(*arg) && !got_int) - { - if (error || eap->skip) - { - arg = find_name_end(arg, NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); - if (!VIM_ISWHITE(*arg) && !ends_excmd(*arg)) - { - emsg_severe = TRUE; - emsg(_(e_trailing)); - break; - } - } - else - { - /* get_name_len() takes care of expanding curly braces */ - name_start = name = arg; - len = get_name_len(&arg, &tofree, TRUE, TRUE); - if (len <= 0) - { - /* This is mainly to keep test 49 working: when expanding - * curly braces fails overrule the exception error message. */ - if (len < 0 && !aborting()) - { - emsg_severe = TRUE; - semsg(_(e_invarg2), arg); - break; - } - error = TRUE; - } - else - { - if (tofree != NULL) - name = tofree; - if (get_var_tv(name, len, &tv, NULL, TRUE, FALSE) == FAIL) - error = TRUE; - else - { - /* handle d.key, l[idx], f(expr) */ - arg_subsc = arg; - if (handle_subscript(&arg, &tv, TRUE, TRUE, - name, &name) == FAIL) - error = TRUE; - else - { - if (arg == arg_subsc && len == 2 && name[1] == ':') - { - switch (*name) - { - case 'g': list_glob_vars(first); break; - case 'b': list_buf_vars(first); break; - case 'w': list_win_vars(first); break; - case 't': list_tab_vars(first); break; - case 'v': list_vim_vars(first); break; - case 's': list_script_vars(first); break; - case 'l': list_func_vars(first); break; - default: - semsg(_("E738: Can't list variables for %s"), name); - } - } - else - { - char_u numbuf[NUMBUFLEN]; - char_u *tf; - int c; - char_u *s; - - s = echo_string(&tv, &tf, numbuf, 0); - c = *arg; - *arg = NUL; - list_one_var_a("", - arg == arg_subsc ? name : name_start, - tv.v_type, - s == NULL ? (char_u *)"" : s, - first); - *arg = c; - vim_free(tf); - } - clear_tv(&tv); - } - } - } - - vim_free(tofree); - } - - arg = skipwhite(arg); - } - - return arg; - } - - /* - * Set one item of ":let var = expr" or ":let [v1, v2] = list" to its value. - * Returns a pointer to the char just after the var name. - * Returns NULL if there is an error. - */ - static char_u * - ex_let_one( - char_u *arg, // points to variable name - typval_T *tv, // value to assign to variable - int copy, // copy value from "tv" - int is_const, // lock variable for const - char_u *endchars, // valid chars after variable name or NULL - char_u *op) // "+", "-", "." or NULL - { - int c1; - char_u *name; - char_u *p; - char_u *arg_end = NULL; - int len; - int opt_flags; - char_u *tofree = NULL; - - /* - * ":let $VAR = expr": Set environment variable. - */ - if (*arg == '$') - { - if (is_const) - { - emsg(_("E996: Cannot lock an environment variable")); - return NULL; - } - /* Find the end of the name. */ - ++arg; - name = arg; - len = get_env_len(&arg); - if (len == 0) - semsg(_(e_invarg2), name - 1); - else - { - if (op != NULL && vim_strchr((char_u *)"+-*/%", *op) != NULL) - semsg(_(e_letwrong), op); - else if (endchars != NULL - && vim_strchr(endchars, *skipwhite(arg)) == NULL) - emsg(_(e_letunexp)); - else if (!check_secure()) - { - c1 = name[len]; - name[len] = NUL; - p = tv_get_string_chk(tv); - if (p != NULL && op != NULL && *op == '.') - { - int mustfree = FALSE; - char_u *s = vim_getenv(name, &mustfree); - - if (s != NULL) - { - p = tofree = concat_str(s, p); - if (mustfree) - vim_free(s); - } - } - if (p != NULL) - { - vim_setenv(name, p); - if (STRICMP(name, "HOME") == 0) - init_homedir(); - else if (didset_vim && STRICMP(name, "VIM") == 0) - didset_vim = FALSE; - else if (didset_vimruntime - && STRICMP(name, "VIMRUNTIME") == 0) - didset_vimruntime = FALSE; - arg_end = arg; - } - name[len] = c1; - vim_free(tofree); - } - } - } - - /* - * ":let &option = expr": Set option value. - * ":let &l:option = expr": Set local option value. - * ":let &g:option = expr": Set global option value. - */ - else if (*arg == '&') - { - if (is_const) - { - emsg(_("E996: Cannot lock an option")); - return NULL; - } - /* Find the end of the name. */ - p = find_option_end(&arg, &opt_flags); - if (p == NULL || (endchars != NULL - && vim_strchr(endchars, *skipwhite(p)) == NULL)) - emsg(_(e_letunexp)); - else - { - long n; - int opt_type; - long numval; - char_u *stringval = NULL; - char_u *s; - - c1 = *p; - *p = NUL; - - n = (long)tv_get_number(tv); - s = tv_get_string_chk(tv); /* != NULL if number or string */ - if (s != NULL && op != NULL && *op != '=') - { - opt_type = get_option_value(arg, &numval, - &stringval, opt_flags); - if ((opt_type == 1 && *op == '.') - || (opt_type == 0 && *op != '.')) - { - semsg(_(e_letwrong), op); - s = NULL; // don't set the value - } - else - { - if (opt_type == 1) // number - { - switch (*op) - { - case '+': n = numval + n; break; - case '-': n = numval - n; break; - case '*': n = numval * n; break; - case '/': n = (long)num_divide(numval, n); break; - case '%': n = (long)num_modulus(numval, n); break; - } - } - else if (opt_type == 0 && stringval != NULL) // string - { - s = concat_str(stringval, s); - vim_free(stringval); - stringval = s; - } - } - } - if (s != NULL) - { - set_option_value(arg, n, s, opt_flags); - arg_end = p; - } - *p = c1; - vim_free(stringval); - } - } - - /* - * ":let @r = expr": Set register contents. - */ - else if (*arg == '@') - { - if (is_const) - { - emsg(_("E996: Cannot lock a register")); - return NULL; - } - ++arg; - if (op != NULL && vim_strchr((char_u *)"+-*/%", *op) != NULL) - semsg(_(e_letwrong), op); - else if (endchars != NULL - && vim_strchr(endchars, *skipwhite(arg + 1)) == NULL) - emsg(_(e_letunexp)); - else - { - char_u *ptofree = NULL; - char_u *s; - - p = tv_get_string_chk(tv); - if (p != NULL && op != NULL && *op == '.') - { - s = get_reg_contents(*arg == '@' ? '"' : *arg, GREG_EXPR_SRC); - if (s != NULL) - { - p = ptofree = concat_str(s, p); - vim_free(s); - } - } - if (p != NULL) - { - write_reg_contents(*arg == '@' ? '"' : *arg, p, -1, FALSE); - arg_end = arg + 1; - } - vim_free(ptofree); - } - } - - /* - * ":let var = expr": Set internal variable. - * ":let {expr} = expr": Idem, name made with curly braces - */ - else if (eval_isnamec1(*arg) || *arg == '{') - { - lval_T lv; - - p = get_lval(arg, tv, &lv, FALSE, FALSE, 0, FNE_CHECK_START); - if (p != NULL && lv.ll_name != NULL) - { - if (endchars != NULL && vim_strchr(endchars, *skipwhite(p)) == NULL) - emsg(_(e_letunexp)); - else - { - set_var_lval(&lv, p, tv, copy, is_const, op); - arg_end = p; - } - } - clear_lval(&lv); - } - - else - semsg(_(e_invarg2), arg); - - return arg_end; - } - - /* * Get an lval: variable, Dict item or List item that can be assigned a value * to: "name", "na{me}", "name[expr]", "name[expr:expr]", "name[expr][expr]", * "name.key", "name.key[expr]" etc. --- 1236,1241 ---- *************** *** 2502,2508 **** * "op" is NULL, "+" for "+=", "-" for "-=", "*" for "*=", "/" for "/=", * "%" for "%=", "." for ".=" or "=" for "=". */ ! static void set_var_lval( lval_T *lp, char_u *endp, --- 1658,1664 ---- * "op" is NULL, "+" for "+=", "-" for "-=", "*" for "*=", "/" for "/=", * "%" for "%=", "." for ".=" or "=" for "=". */ ! void set_var_lval( lval_T *lp, char_u *endp, *************** *** 3105,3482 **** xp->xp_pattern = arg; } - /* - * ":unlet[!] var1 ... " command. - */ - void - ex_unlet(exarg_T *eap) - { - ex_unletlock(eap, eap->arg, 0); - } - - /* - * ":lockvar" and ":unlockvar" commands - */ - void - ex_lockvar(exarg_T *eap) - { - char_u *arg = eap->arg; - int deep = 2; - - if (eap->forceit) - deep = -1; - else if (vim_isdigit(*arg)) - { - deep = getdigits(&arg); - arg = skipwhite(arg); - } - - ex_unletlock(eap, arg, deep); - } - - /* - * ":unlet", ":lockvar" and ":unlockvar" are quite similar. - */ - static void - ex_unletlock( - exarg_T *eap, - char_u *argstart, - int deep) - { - char_u *arg = argstart; - char_u *name_end; - int error = FALSE; - lval_T lv; - - do - { - if (*arg == '$') - { - char_u *name = ++arg; - - if (get_env_len(&arg) == 0) - { - semsg(_(e_invarg2), name - 1); - return; - } - vim_unsetenv(name); - arg = skipwhite(arg); - continue; - } - - /* Parse the name and find the end. */ - name_end = get_lval(arg, NULL, &lv, TRUE, eap->skip || error, 0, - FNE_CHECK_START); - if (lv.ll_name == NULL) - error = TRUE; /* error but continue parsing */ - if (name_end == NULL || (!VIM_ISWHITE(*name_end) - && !ends_excmd(*name_end))) - { - if (name_end != NULL) - { - emsg_severe = TRUE; - emsg(_(e_trailing)); - } - if (!(eap->skip || error)) - clear_lval(&lv); - break; - } - - if (!error && !eap->skip) - { - if (eap->cmdidx == CMD_unlet) - { - if (do_unlet_var(&lv, name_end, eap->forceit) == FAIL) - error = TRUE; - } - else - { - if (do_lock_var(&lv, name_end, deep, - eap->cmdidx == CMD_lockvar) == FAIL) - error = TRUE; - } - } - - if (!eap->skip) - clear_lval(&lv); - - arg = skipwhite(name_end); - } while (!ends_excmd(*arg)); - - eap->nextcmd = check_nextcmd(arg); - } - - static int - do_unlet_var( - lval_T *lp, - char_u *name_end, - int forceit) - { - int ret = OK; - int cc; - - if (lp->ll_tv == NULL) - { - cc = *name_end; - *name_end = NUL; - - /* Normal name or expanded name. */ - if (do_unlet(lp->ll_name, forceit) == FAIL) - ret = FAIL; - *name_end = cc; - } - else if ((lp->ll_list != NULL - && var_check_lock(lp->ll_list->lv_lock, lp->ll_name, FALSE)) - || (lp->ll_dict != NULL - && var_check_lock(lp->ll_dict->dv_lock, lp->ll_name, FALSE))) - return FAIL; - else if (lp->ll_range) - { - listitem_T *li; - listitem_T *ll_li = lp->ll_li; - int ll_n1 = lp->ll_n1; - - while (ll_li != NULL && (lp->ll_empty2 || lp->ll_n2 >= ll_n1)) - { - li = ll_li->li_next; - if (var_check_lock(ll_li->li_tv.v_lock, lp->ll_name, FALSE)) - return FAIL; - ll_li = li; - ++ll_n1; - } - - /* Delete a range of List items. */ - while (lp->ll_li != NULL && (lp->ll_empty2 || lp->ll_n2 >= lp->ll_n1)) - { - li = lp->ll_li->li_next; - listitem_remove(lp->ll_list, lp->ll_li); - lp->ll_li = li; - ++lp->ll_n1; - } - } - else - { - if (lp->ll_list != NULL) - /* unlet a List item. */ - listitem_remove(lp->ll_list, lp->ll_li); - else - /* unlet a Dictionary item. */ - dictitem_remove(lp->ll_dict, lp->ll_di); - } - - return ret; - } - - /* - * "unlet" a variable. Return OK if it existed, FAIL if not. - * When "forceit" is TRUE don't complain if the variable doesn't exist. - */ - int - do_unlet(char_u *name, int forceit) - { - hashtab_T *ht; - hashitem_T *hi; - char_u *varname; - dict_T *d; - dictitem_T *di; - - ht = find_var_ht(name, &varname); - if (ht != NULL && *varname != NUL) - { - d = get_current_funccal_dict(ht); - if (d == NULL) - { - if (ht == &globvarht) - d = &globvardict; - else if (ht == &compat_hashtab) - d = &vimvardict; - else - { - di = find_var_in_ht(ht, *name, (char_u *)"", FALSE); - d = di == NULL ? NULL : di->di_tv.vval.v_dict; - } - if (d == NULL) - { - internal_error("do_unlet()"); - return FAIL; - } - } - hi = hash_find(ht, varname); - if (HASHITEM_EMPTY(hi)) - hi = find_hi_in_scoped_ht(name, &ht); - if (hi != NULL && !HASHITEM_EMPTY(hi)) - { - di = HI2DI(hi); - if (var_check_fixed(di->di_flags, name, FALSE) - || var_check_ro(di->di_flags, name, FALSE) - || var_check_lock(d->dv_lock, name, FALSE)) - return FAIL; - - delete_var(ht, hi); - return OK; - } - } - if (forceit) - return OK; - semsg(_("E108: No such variable: \"%s\""), name); - return FAIL; - } - - /* - * Lock or unlock variable indicated by "lp". - * "deep" is the levels to go (-1 for unlimited); - * "lock" is TRUE for ":lockvar", FALSE for ":unlockvar". - */ - static int - do_lock_var( - lval_T *lp, - char_u *name_end, - int deep, - int lock) - { - int ret = OK; - int cc; - dictitem_T *di; - - if (deep == 0) /* nothing to do */ - return OK; - - if (lp->ll_tv == NULL) - { - cc = *name_end; - *name_end = NUL; - - /* Normal name or expanded name. */ - di = find_var(lp->ll_name, NULL, TRUE); - if (di == NULL) - ret = FAIL; - else if ((di->di_flags & DI_FLAGS_FIX) - && di->di_tv.v_type != VAR_DICT - && di->di_tv.v_type != VAR_LIST) - /* For historic reasons this error is not given for a list or dict. - * E.g., the b: dict could be locked/unlocked. */ - semsg(_("E940: Cannot lock or unlock variable %s"), lp->ll_name); - else - { - if (lock) - di->di_flags |= DI_FLAGS_LOCK; - else - di->di_flags &= ~DI_FLAGS_LOCK; - item_lock(&di->di_tv, deep, lock); - } - *name_end = cc; - } - else if (lp->ll_range) - { - listitem_T *li = lp->ll_li; - - /* (un)lock a range of List items. */ - while (li != NULL && (lp->ll_empty2 || lp->ll_n2 >= lp->ll_n1)) - { - item_lock(&li->li_tv, deep, lock); - li = li->li_next; - ++lp->ll_n1; - } - } - else if (lp->ll_list != NULL) - /* (un)lock a List item. */ - item_lock(&lp->ll_li->li_tv, deep, lock); - else - /* (un)lock a Dictionary item. */ - item_lock(&lp->ll_di->di_tv, deep, lock); - - return ret; - } - - /* - * Lock or unlock an item. "deep" is nr of levels to go. - */ - static void - item_lock(typval_T *tv, int deep, int lock) - { - static int recurse = 0; - list_T *l; - listitem_T *li; - dict_T *d; - blob_T *b; - hashitem_T *hi; - int todo; - - if (recurse >= DICT_MAXNEST) - { - emsg(_("E743: variable nested too deep for (un)lock")); - return; - } - if (deep == 0) - return; - ++recurse; - - /* lock/unlock the item itself */ - if (lock) - tv->v_lock |= VAR_LOCKED; - else - tv->v_lock &= ~VAR_LOCKED; - - switch (tv->v_type) - { - case VAR_UNKNOWN: - case VAR_NUMBER: - case VAR_STRING: - case VAR_FUNC: - case VAR_PARTIAL: - case VAR_FLOAT: - case VAR_SPECIAL: - case VAR_JOB: - case VAR_CHANNEL: - break; - - case VAR_BLOB: - if ((b = tv->vval.v_blob) != NULL) - { - if (lock) - b->bv_lock |= VAR_LOCKED; - else - b->bv_lock &= ~VAR_LOCKED; - } - break; - case VAR_LIST: - if ((l = tv->vval.v_list) != NULL) - { - if (lock) - l->lv_lock |= VAR_LOCKED; - else - l->lv_lock &= ~VAR_LOCKED; - if (deep < 0 || deep > 1) - /* recursive: lock/unlock the items the List contains */ - for (li = l->lv_first; li != NULL; li = li->li_next) - item_lock(&li->li_tv, deep - 1, lock); - } - break; - case VAR_DICT: - if ((d = tv->vval.v_dict) != NULL) - { - if (lock) - d->dv_lock |= VAR_LOCKED; - else - d->dv_lock &= ~VAR_LOCKED; - if (deep < 0 || deep > 1) - { - /* recursive: lock/unlock the items the List contains */ - todo = (int)d->dv_hashtab.ht_used; - for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) - { - if (!HASHITEM_EMPTY(hi)) - { - --todo; - item_lock(&HI2DI(hi)->di_tv, deep - 1, lock); - } - } - } - } - } - --recurse; - } - #if (defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)) || defined(PROTO) /* * Delete all "menutrans_" variables. --- 2261,2266 ---- *************** *** 6871,6877 **** * Advance "arg" to the first character after the name. * Return 0 for error. */ ! static int get_env_len(char_u **arg) { char_u *p; --- 5655,5661 ---- * Advance "arg" to the first character after the name. * Return 0 for error. */ ! int get_env_len(char_u **arg) { char_u *p; *************** *** 6929,6935 **** * If the name contains 'magic' {}'s, expand them and return the * expanded name in an allocated string via 'alias' - caller must free. */ ! static int get_name_len( char_u **arg, char_u **alias, --- 5713,5719 ---- * If the name contains 'magic' {}'s, expand them and return the * expanded name in an allocated string via 'alias' - caller must free. */ ! int get_name_len( char_u **arg, char_u **alias, *************** *** 7455,7507 **** } /* - * Get the value of internal variable "name". - * Return OK or FAIL. If OK is returned "rettv" must be cleared. - */ - static int - get_var_tv( - char_u *name, - int len, /* length of "name" */ - typval_T *rettv, /* NULL when only checking existence */ - dictitem_T **dip, /* non-NULL when typval's dict item is needed */ - int verbose, /* may give error message */ - int no_autoload) /* do not use script autoloading */ - { - int ret = OK; - typval_T *tv = NULL; - dictitem_T *v; - int cc; - - /* truncate the name, so that we can use strcmp() */ - cc = name[len]; - name[len] = NUL; - - /* - * Check for user-defined variables. - */ - v = find_var(name, NULL, no_autoload); - if (v != NULL) - { - tv = &v->di_tv; - if (dip != NULL) - *dip = v; - } - - if (tv == NULL) - { - if (rettv != NULL && verbose) - semsg(_(e_undefvar), name); - ret = FAIL; - } - else if (rettv != NULL) - copy_tv(tv, rettv); - - name[len] = cc; - - return ret; - } - - /* * Check if variable "name[len]" is a local variable or an argument. * If so, "*eval_lavars_used" is set to TRUE. */ --- 6239,6244 ---- *************** *** 8177,8198 **** } /* - * Get the string value of a (global/local) variable. - * Note: see tv_get_string() for how long the pointer remains valid. - * Returns NULL when it doesn't exist. - */ - char_u * - get_var_value(char_u *name) - { - dictitem_T *v; - - v = find_var(name, NULL, FALSE); - if (v == NULL) - return NULL; - return tv_get_string(&v->di_tv); - } - - /* * Allocate a new hashtab for a sourced script. It will be used while * sourcing this script and when executing functions defined in the script. */ --- 6914,6919 ---- *************** *** 8259,8623 **** } /* - * Clean up a list of internal variables. - * Frees all allocated variables and the value they contain. - * Clears hashtab "ht", does not free it. - */ - void - vars_clear(hashtab_T *ht) - { - vars_clear_ext(ht, TRUE); - } - - /* - * Like vars_clear(), but only free the value if "free_val" is TRUE. - */ - void - vars_clear_ext(hashtab_T *ht, int free_val) - { - int todo; - hashitem_T *hi; - dictitem_T *v; - - hash_lock(ht); - todo = (int)ht->ht_used; - for (hi = ht->ht_array; todo > 0; ++hi) - { - if (!HASHITEM_EMPTY(hi)) - { - --todo; - - /* Free the variable. Don't remove it from the hashtab, - * ht_array might change then. hash_clear() takes care of it - * later. */ - v = HI2DI(hi); - if (free_val) - clear_tv(&v->di_tv); - if (v->di_flags & DI_FLAGS_ALLOC) - vim_free(v); - } - } - hash_clear(ht); - ht->ht_used = 0; - } - - /* - * Delete a variable from hashtab "ht" at item "hi". - * Clear the variable value and free the dictitem. - */ - static void - delete_var(hashtab_T *ht, hashitem_T *hi) - { - dictitem_T *di = HI2DI(hi); - - hash_remove(ht, hi); - clear_tv(&di->di_tv); - vim_free(di); - } - - /* - * List the value of one internal variable. - */ - static void - list_one_var(dictitem_T *v, char *prefix, int *first) - { - char_u *tofree; - char_u *s; - char_u numbuf[NUMBUFLEN]; - - s = echo_string(&v->di_tv, &tofree, numbuf, get_copyID()); - list_one_var_a(prefix, v->di_key, v->di_tv.v_type, - s == NULL ? (char_u *)"" : s, first); - vim_free(tofree); - } - - static void - list_one_var_a( - char *prefix, - char_u *name, - int type, - char_u *string, - int *first) /* when TRUE clear rest of screen and set to FALSE */ - { - /* don't use msg() or msg_attr() to avoid overwriting "v:statusmsg" */ - msg_start(); - msg_puts(prefix); - if (name != NULL) /* "a:" vars don't have a name stored */ - msg_puts((char *)name); - msg_putchar(' '); - msg_advance(22); - if (type == VAR_NUMBER) - msg_putchar('#'); - else if (type == VAR_FUNC || type == VAR_PARTIAL) - msg_putchar('*'); - else if (type == VAR_LIST) - { - msg_putchar('['); - if (*string == '[') - ++string; - } - else if (type == VAR_DICT) - { - msg_putchar('{'); - if (*string == '{') - ++string; - } - else - msg_putchar(' '); - - msg_outtrans(string); - - if (type == VAR_FUNC || type == VAR_PARTIAL) - msg_puts("()"); - if (*first) - { - msg_clr_eos(); - *first = FALSE; - } - } - - /* - * Set variable "name" to value in "tv". - * If the variable already exists, the value is updated. - * Otherwise the variable is created. - */ - void - set_var( - char_u *name, - typval_T *tv, - int copy) // make copy of value in "tv" - { - set_var_const(name, tv, copy, FALSE); - } - - /* - * Set variable "name" to value in "tv". - * If the variable already exists and "is_const" is FALSE the value is updated. - * Otherwise the variable is created. - */ - static void - set_var_const( - char_u *name, - typval_T *tv, - int copy, // make copy of value in "tv" - int is_const) // disallow to modify existing variable - { - dictitem_T *v; - char_u *varname; - hashtab_T *ht; - - ht = find_var_ht(name, &varname); - if (ht == NULL || *varname == NUL) - { - semsg(_(e_illvar), name); - return; - } - v = find_var_in_ht(ht, 0, varname, TRUE); - - /* Search in parent scope which is possible to reference from lambda */ - if (v == NULL) - v = find_var_in_scoped_ht(name, TRUE); - - if ((tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL) - && var_check_func_name(name, v == NULL)) - return; - - if (v != NULL) - { - if (is_const) - { - emsg(_(e_cannot_mod)); - return; - } - - /* existing variable, need to clear the value */ - if (var_check_ro(v->di_flags, name, FALSE) - || var_check_lock(v->di_tv.v_lock, name, FALSE)) - return; - - /* - * Handle setting internal v: variables separately where needed to - * prevent changing the type. - */ - if (ht == &vimvarht) - { - if (v->di_tv.v_type == VAR_STRING) - { - VIM_CLEAR(v->di_tv.vval.v_string); - if (copy || tv->v_type != VAR_STRING) - { - char_u *val = tv_get_string(tv); - - // Careful: when assigning to v:errmsg and tv_get_string() - // causes an error message the variable will alrady be set. - if (v->di_tv.vval.v_string == NULL) - v->di_tv.vval.v_string = vim_strsave(val); - } - else - { - /* Take over the string to avoid an extra alloc/free. */ - v->di_tv.vval.v_string = tv->vval.v_string; - tv->vval.v_string = NULL; - } - return; - } - else if (v->di_tv.v_type == VAR_NUMBER) - { - v->di_tv.vval.v_number = tv_get_number(tv); - if (STRCMP(varname, "searchforward") == 0) - set_search_direction(v->di_tv.vval.v_number ? '/' : '?'); - #ifdef FEAT_SEARCH_EXTRA - else if (STRCMP(varname, "hlsearch") == 0) - { - no_hlsearch = !v->di_tv.vval.v_number; - redraw_all_later(SOME_VALID); - } - #endif - return; - } - else if (v->di_tv.v_type != tv->v_type) - { - semsg(_("E963: setting %s to value with wrong type"), name); - return; - } - } - - clear_tv(&v->di_tv); - } - else /* add a new variable */ - { - // Can't add "v:" or "a:" variable. - if (ht == &vimvarht || ht == get_funccal_args_ht()) - { - semsg(_(e_illvar), name); - return; - } - - // Make sure the variable name is valid. - if (!valid_varname(varname)) - return; - - v = alloc(sizeof(dictitem_T) + STRLEN(varname)); - if (v == NULL) - return; - STRCPY(v->di_key, varname); - if (hash_add(ht, DI2HIKEY(v)) == FAIL) - { - vim_free(v); - return; - } - v->di_flags = DI_FLAGS_ALLOC; - if (is_const) - v->di_flags |= DI_FLAGS_LOCK; - } - - if (copy || tv->v_type == VAR_NUMBER || tv->v_type == VAR_FLOAT) - copy_tv(tv, &v->di_tv); - else - { - v->di_tv = *tv; - v->di_tv.v_lock = 0; - init_tv(tv); - } - - if (is_const) - v->di_tv.v_lock |= VAR_LOCKED; - } - - /* - * Return TRUE if di_flags "flags" indicates variable "name" is read-only. - * Also give an error message. - */ - int - var_check_ro(int flags, char_u *name, int use_gettext) - { - if (flags & DI_FLAGS_RO) - { - semsg(_(e_readonlyvar), use_gettext ? (char_u *)_(name) : name); - return TRUE; - } - if ((flags & DI_FLAGS_RO_SBX) && sandbox) - { - semsg(_(e_readonlysbx), use_gettext ? (char_u *)_(name) : name); - return TRUE; - } - return FALSE; - } - - /* - * Return TRUE if di_flags "flags" indicates variable "name" is fixed. - * Also give an error message. - */ - int - var_check_fixed(int flags, char_u *name, int use_gettext) - { - if (flags & DI_FLAGS_FIX) - { - semsg(_("E795: Cannot delete variable %s"), - use_gettext ? (char_u *)_(name) : name); - return TRUE; - } - return FALSE; - } - - /* - * Check if a funcref is assigned to a valid variable name. - * Return TRUE and give an error if not. - */ - int - var_check_func_name( - char_u *name, /* points to start of variable name */ - int new_var) /* TRUE when creating the variable */ - { - /* Allow for w: b: s: and t:. */ - if (!(vim_strchr((char_u *)"wbst", name[0]) != NULL && name[1] == ':') - && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':') - ? name[2] : name[0])) - { - semsg(_("E704: Funcref variable name must start with a capital: %s"), - name); - return TRUE; - } - /* Don't allow hiding a function. When "v" is not NULL we might be - * assigning another function to the same var, the type is checked - * below. */ - if (new_var && function_exists(name, FALSE)) - { - semsg(_("E705: Variable name conflicts with existing function: %s"), - name); - return TRUE; - } - return FALSE; - } - - /* - * Return TRUE if "flags" indicates variable "name" is locked (immutable). - * Also give an error message, using "name" or _("name") when use_gettext is - * TRUE. - */ - int - var_check_lock(int lock, char_u *name, int use_gettext) - { - if (lock & VAR_LOCKED) - { - semsg(_("E741: Value is locked: %s"), - name == NULL ? (char_u *)_("Unknown") - : use_gettext ? (char_u *)_(name) - : name); - return TRUE; - } - if (lock & VAR_FIXED) - { - semsg(_("E742: Cannot change value of %s"), - name == NULL ? (char_u *)_("Unknown") - : use_gettext ? (char_u *)_(name) - : name); - return TRUE; - } - return FALSE; - } - - /* * Return TRUE if typeval "tv" and its value are set to be locked (immutable). * Also give an error message, using "name" or _("name") when use_gettext is * TRUE. --- 6980,6985 ---- *************** *** 8649,8673 **** } /* - * Check if a variable name is valid. - * Return FALSE and give an error if not. - */ - int - valid_varname(char_u *varname) - { - char_u *p; - - for (p = varname; *p != NUL; ++p) - if (!eval_isnamec1(*p) && (p == varname || !VIM_ISDIGIT(*p)) - && *p != AUTOLOAD_CHAR) - { - semsg(_(e_illvar), varname); - return FALSE; - } - return TRUE; - } - - /* * Copy the values from typval_T "from" to typval_T "to". * When needed allocates string or increases reference count. * Does not make a copy of a list, blob or dict but copies the reference! --- 7011,7016 ---- *************** *** 9250,9403 **** } /* - * getwinvar() and gettabwinvar() - */ - void - getwinvar( - typval_T *argvars, - typval_T *rettv, - int off) /* 1 for gettabwinvar() */ - { - win_T *win; - char_u *varname; - dictitem_T *v; - tabpage_T *tp = NULL; - int done = FALSE; - win_T *oldcurwin; - tabpage_T *oldtabpage; - int need_switch_win; - - if (off == 1) - tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL)); - else - tp = curtab; - win = find_win_by_nr(&argvars[off], tp); - varname = tv_get_string_chk(&argvars[off + 1]); - ++emsg_off; - - rettv->v_type = VAR_STRING; - rettv->vval.v_string = NULL; - - if (win != NULL && varname != NULL) - { - /* Set curwin to be our win, temporarily. Also set the tabpage, - * otherwise the window is not valid. Only do this when needed, - * autocommands get blocked. */ - need_switch_win = !(tp == curtab && win == curwin); - if (!need_switch_win - || switch_win(&oldcurwin, &oldtabpage, win, tp, TRUE) == OK) - { - if (*varname == '&') - { - if (varname[1] == NUL) - { - /* get all window-local options in a dict */ - dict_T *opts = get_winbuf_options(FALSE); - - if (opts != NULL) - { - rettv_dict_set(rettv, opts); - done = TRUE; - } - } - else if (get_option_tv(&varname, rettv, 1) == OK) - /* window-local-option */ - done = TRUE; - } - else - { - /* Look up the variable. */ - /* Let getwinvar({nr}, "") return the "w:" dictionary. */ - v = find_var_in_ht(&win->w_vars->dv_hashtab, 'w', - varname, FALSE); - if (v != NULL) - { - copy_tv(&v->di_tv, rettv); - done = TRUE; - } - } - } - - if (need_switch_win) - /* restore previous notion of curwin */ - restore_win(oldcurwin, oldtabpage, TRUE); - } - - if (!done && argvars[off + 2].v_type != VAR_UNKNOWN) - /* use the default return value */ - copy_tv(&argvars[off + 2], rettv); - - --emsg_off; - } - - /* - * "setwinvar()" and "settabwinvar()" functions - */ - void - setwinvar(typval_T *argvars, typval_T *rettv UNUSED, int off) - { - win_T *win; - win_T *save_curwin; - tabpage_T *save_curtab; - int need_switch_win; - char_u *varname, *winvarname; - typval_T *varp; - char_u nbuf[NUMBUFLEN]; - tabpage_T *tp = NULL; - - if (check_secure()) - return; - - if (off == 1) - tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL)); - else - tp = curtab; - win = find_win_by_nr(&argvars[off], tp); - varname = tv_get_string_chk(&argvars[off + 1]); - varp = &argvars[off + 2]; - - if (win != NULL && varname != NULL && varp != NULL) - { - need_switch_win = !(tp == curtab && win == curwin); - if (!need_switch_win - || switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == OK) - { - if (*varname == '&') - { - long numval; - char_u *strval; - int error = FALSE; - - ++varname; - numval = (long)tv_get_number_chk(varp, &error); - strval = tv_get_string_buf_chk(varp, nbuf); - if (!error && strval != NULL) - set_option_value(varname, numval, strval, OPT_LOCAL); - } - else - { - winvarname = alloc(STRLEN(varname) + 3); - if (winvarname != NULL) - { - STRCPY(winvarname, "w:"); - STRCPY(winvarname + 2, varname); - set_var(winvarname, varp, TRUE); - vim_free(winvarname); - } - } - } - if (need_switch_win) - restore_win(save_curwin, save_curtab, TRUE); - } - } - - /* * Skip over the name of an option: "&option", "&g:option" or "&l:option". * "arg" points to the "&" or '+' when called, to "option" when returning. * Returns NULL when no option name found. Otherwise pointer to the char * after the option name. */ ! static char_u * find_option_end(char_u **arg, int *opt_flags) { char_u *p = *arg; --- 7593,7604 ---- } /* * Skip over the name of an option: "&option", "&g:option" or "&l:option". * "arg" points to the "&" or '+' when called, to "option" when returning. * Returns NULL when no option name found. Otherwise pointer to the char * after the option name. */ ! char_u * find_option_end(char_u **arg, int *opt_flags) { char_u *p = *arg; *************** *** 9797,9834 **** return ret; } - int - var_exists(char_u *var) - { - char_u *name; - char_u *tofree; - typval_T tv; - int len = 0; - int n = FALSE; - - /* get_name_len() takes care of expanding curly braces */ - name = var; - len = get_name_len(&var, &tofree, TRUE, FALSE); - if (len > 0) - { - if (tofree != NULL) - name = tofree; - n = (get_var_tv(name, len, &tv, NULL, FALSE, TRUE) == OK); - if (n) - { - /* handle d.key, l[idx], f(expr) */ - n = (handle_subscript(&var, &tv, TRUE, FALSE, name, &name) == OK); - if (n) - clear_tv(&tv); - } - } - if (*var != NUL) - n = FALSE; - - vim_free(tofree); - return n; - } - #endif /* FEAT_EVAL */ --- 7998,8003 ---- *** ../vim-8.1.1932/src/evalfunc.c 2019-08-27 21:56:01.699592495 +0200 --- src/evalfunc.c 2019-08-27 22:37:44.277253720 +0200 *************** *** 155,168 **** static void f_getreg(typval_T *argvars, typval_T *rettv); static void f_getregtype(typval_T *argvars, typval_T *rettv); static void f_gettabinfo(typval_T *argvars, typval_T *rettv); - static void f_gettabvar(typval_T *argvars, typval_T *rettv); - static void f_gettabwinvar(typval_T *argvars, typval_T *rettv); static void f_gettagstack(typval_T *argvars, typval_T *rettv); static void f_getwininfo(typval_T *argvars, typval_T *rettv); static void f_getwinpos(typval_T *argvars, typval_T *rettv); static void f_getwinposx(typval_T *argvars, typval_T *rettv); static void f_getwinposy(typval_T *argvars, typval_T *rettv); - static void f_getwinvar(typval_T *argvars, typval_T *rettv); static void f_glob(typval_T *argvars, typval_T *rettv); static void f_globpath(typval_T *argvars, typval_T *rettv); static void f_glob2regpat(typval_T *argvars, typval_T *rettv); --- 155,165 ---- *************** *** 293,302 **** static void f_setpos(typval_T *argvars, typval_T *rettv); static void f_setqflist(typval_T *argvars, typval_T *rettv); static void f_setreg(typval_T *argvars, typval_T *rettv); - static void f_settabvar(typval_T *argvars, typval_T *rettv); - static void f_settabwinvar(typval_T *argvars, typval_T *rettv); static void f_settagstack(typval_T *argvars, typval_T *rettv); - static void f_setwinvar(typval_T *argvars, typval_T *rettv); #ifdef FEAT_CRYPT static void f_sha256(typval_T *argvars, typval_T *rettv); #endif /* FEAT_CRYPT */ --- 290,296 ---- *************** *** 5315,5372 **** } /* - * "gettabvar()" function - */ - static void - f_gettabvar(typval_T *argvars, typval_T *rettv) - { - win_T *oldcurwin; - tabpage_T *tp, *oldtabpage; - dictitem_T *v; - char_u *varname; - int done = FALSE; - - rettv->v_type = VAR_STRING; - rettv->vval.v_string = NULL; - - varname = tv_get_string_chk(&argvars[1]); - tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL)); - if (tp != NULL && varname != NULL) - { - /* Set tp to be our tabpage, temporarily. Also set the window to the - * first window in the tabpage, otherwise the window is not valid. */ - if (switch_win(&oldcurwin, &oldtabpage, - tp == curtab || tp->tp_firstwin == NULL ? firstwin - : tp->tp_firstwin, tp, TRUE) == OK) - { - /* look up the variable */ - /* Let gettabvar({nr}, "") return the "t:" dictionary. */ - v = find_var_in_ht(&tp->tp_vars->dv_hashtab, 't', varname, FALSE); - if (v != NULL) - { - copy_tv(&v->di_tv, rettv); - done = TRUE; - } - } - - /* restore previous notion of curwin */ - restore_win(oldcurwin, oldtabpage, TRUE); - } - - if (!done && argvars[2].v_type != VAR_UNKNOWN) - copy_tv(&argvars[2], rettv); - } - - /* - * "gettabwinvar()" function - */ - static void - f_gettabwinvar(typval_T *argvars, typval_T *rettv) - { - getwinvar(argvars, rettv, 1); - } - - /* * "gettagstack()" function */ static void --- 5309,5314 ---- *************** *** 5625,5639 **** } /* - * "getwinvar()" function - */ - static void - f_getwinvar(typval_T *argvars, typval_T *rettv) - { - getwinvar(argvars, rettv, 0); - } - - /* * "glob()" function */ static void --- 5567,5572 ---- *************** *** 10243,10297 **** } /* - * "settabvar()" function - */ - static void - f_settabvar(typval_T *argvars, typval_T *rettv) - { - tabpage_T *save_curtab; - tabpage_T *tp; - char_u *varname, *tabvarname; - typval_T *varp; - - rettv->vval.v_number = 0; - - if (check_secure()) - return; - - tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL)); - varname = tv_get_string_chk(&argvars[1]); - varp = &argvars[2]; - - if (varname != NULL && varp != NULL && tp != NULL) - { - save_curtab = curtab; - goto_tabpage_tp(tp, FALSE, FALSE); - - tabvarname = alloc(STRLEN(varname) + 3); - if (tabvarname != NULL) - { - STRCPY(tabvarname, "t:"); - STRCPY(tabvarname + 2, varname); - set_var(tabvarname, varp, TRUE); - vim_free(tabvarname); - } - - /* Restore current tabpage */ - if (valid_tabpage(save_curtab)) - goto_tabpage_tp(save_curtab, FALSE, FALSE); - } - } - - /* - * "settabwinvar()" function - */ - static void - f_settabwinvar(typval_T *argvars, typval_T *rettv) - { - setwinvar(argvars, rettv, 1); - } - - /* * "settagstack()" function */ static void --- 10176,10181 ---- *************** *** 10347,10361 **** rettv->vval.v_number = 0; } - /* - * "setwinvar()" function - */ - static void - f_setwinvar(typval_T *argvars, typval_T *rettv) - { - setwinvar(argvars, rettv, 0); - } - #ifdef FEAT_CRYPT /* * "sha256({string})" function --- 10231,10236 ---- *** ../vim-8.1.1932/src/evalvars.c 2019-08-27 22:47:03.078089415 +0200 --- src/evalvars.c 2019-08-27 22:39:21.396718069 +0200 *************** *** 0 **** --- 1,1946 ---- + /* vi:set ts=8 sts=4 sw=4 noet: + * + * VIM - Vi IMproved by Bram Moolenaar + * + * Do ":help uganda" in Vim to read copying and usage conditions. + * Do ":help credits" in Vim to see a list of people who contributed. + * See README.txt for an overview of the Vim source code. + */ + + /* + * evalvars.c: functions for dealing with variables + */ + + #include "vim.h" + + #if defined(FEAT_EVAL) || defined(PROTO) + + static char *e_letunexp = N_("E18: Unexpected characters in :let"); + + static void ex_let_const(exarg_T *eap, int is_const); + static char_u *skip_var_one(char_u *arg); + static void list_glob_vars(int *first); + static void list_buf_vars(int *first); + static void list_win_vars(int *first); + static void list_tab_vars(int *first); + static char_u *list_arg_vars(exarg_T *eap, char_u *arg, int *first); + static char_u *ex_let_one(char_u *arg, typval_T *tv, int copy, int is_const, char_u *endchars, char_u *op); + static void ex_unletlock(exarg_T *eap, char_u *argstart, int deep); + static int do_unlet_var(lval_T *lp, char_u *name_end, int forceit); + static int do_lock_var(lval_T *lp, char_u *name_end, int deep, int lock); + static void item_lock(typval_T *tv, int deep, int lock); + static void list_one_var(dictitem_T *v, char *prefix, int *first); + static void list_one_var_a(char *prefix, char_u *name, int type, char_u *string, int *first); + + /* + * Get a list of lines from a HERE document. The here document is a list of + * lines surrounded by a marker. + * cmd << {marker} + * {line1} + * {line2} + * .... + * {marker} + * + * The {marker} is a string. If the optional 'trim' word is supplied before the + * marker, then the leading indentation before the lines (matching the + * indentation in the 'cmd' line) is stripped. + * Returns a List with {lines} or NULL. + */ + static list_T * + heredoc_get(exarg_T *eap, char_u *cmd) + { + char_u *theline; + char_u *marker; + list_T *l; + char_u *p; + int marker_indent_len = 0; + int text_indent_len = 0; + char_u *text_indent = NULL; + + if (eap->getline == NULL) + { + emsg(_("E991: cannot use =<< here")); + return NULL; + } + + // Check for the optional 'trim' word before the marker + cmd = skipwhite(cmd); + if (STRNCMP(cmd, "trim", 4) == 0 && (cmd[4] == NUL || VIM_ISWHITE(cmd[4]))) + { + cmd = skipwhite(cmd + 4); + + // Trim the indentation from all the lines in the here document. + // The amount of indentation trimmed is the same as the indentation of + // the first line after the :let command line. To find the end marker + // the indent of the :let command line is trimmed. + p = *eap->cmdlinep; + while (VIM_ISWHITE(*p)) + { + p++; + marker_indent_len++; + } + text_indent_len = -1; + } + + // The marker is the next word. + if (*cmd != NUL && *cmd != '"') + { + marker = skipwhite(cmd); + p = skiptowhite(marker); + if (*skipwhite(p) != NUL && *skipwhite(p) != '"') + { + emsg(_(e_trailing)); + return NULL; + } + *p = NUL; + if (vim_islower(*marker)) + { + emsg(_("E221: Marker cannot start with lower case letter")); + return NULL; + } + } + else + { + emsg(_("E172: Missing marker")); + return NULL; + } + + l = list_alloc(); + if (l == NULL) + return NULL; + + for (;;) + { + int mi = 0; + int ti = 0; + + theline = eap->getline(NUL, eap->cookie, 0, FALSE); + if (theline == NULL) + { + semsg(_("E990: Missing end marker '%s'"), marker); + break; + } + + // with "trim": skip the indent matching the :let line to find the + // marker + if (marker_indent_len > 0 + && STRNCMP(theline, *eap->cmdlinep, marker_indent_len) == 0) + mi = marker_indent_len; + if (STRCMP(marker, theline + mi) == 0) + { + vim_free(theline); + break; + } + + if (text_indent_len == -1 && *theline != NUL) + { + // set the text indent from the first line. + p = theline; + text_indent_len = 0; + while (VIM_ISWHITE(*p)) + { + p++; + text_indent_len++; + } + text_indent = vim_strnsave(theline, text_indent_len); + } + // with "trim": skip the indent matching the first line + if (text_indent != NULL) + for (ti = 0; ti < text_indent_len; ++ti) + if (theline[ti] != text_indent[ti]) + break; + + if (list_append_string(l, theline + ti, -1) == FAIL) + break; + vim_free(theline); + } + vim_free(text_indent); + + return l; + } + + /* + * ":let" list all variable values + * ":let var1 var2" list variable values + * ":let var = expr" assignment command. + * ":let var += expr" assignment command. + * ":let var -= expr" assignment command. + * ":let var *= expr" assignment command. + * ":let var /= expr" assignment command. + * ":let var %= expr" assignment command. + * ":let var .= expr" assignment command. + * ":let var ..= expr" assignment command. + * ":let [var1, var2] = expr" unpack list. + */ + void + ex_let(exarg_T *eap) + { + ex_let_const(eap, FALSE); + } + + /* + * ":const" list all variable values + * ":const var1 var2" list variable values + * ":const var = expr" assignment command. + * ":const [var1, var2] = expr" unpack list. + */ + void + ex_const(exarg_T *eap) + { + ex_let_const(eap, TRUE); + } + + static void + ex_let_const(exarg_T *eap, int is_const) + { + char_u *arg = eap->arg; + char_u *expr = NULL; + typval_T rettv; + int i; + int var_count = 0; + int semicolon = 0; + char_u op[2]; + char_u *argend; + int first = TRUE; + int concat; + + argend = skip_var_list(arg, &var_count, &semicolon); + if (argend == NULL) + return; + if (argend > arg && argend[-1] == '.') // for var.='str' + --argend; + expr = skipwhite(argend); + concat = expr[0] == '.' + && ((expr[1] == '=' && current_sctx.sc_version < 2) + || (expr[1] == '.' && expr[2] == '=')); + if (*expr != '=' && !((vim_strchr((char_u *)"+-*/%", *expr) != NULL + && expr[1] == '=') || concat)) + { + // ":let" without "=": list variables + if (*arg == '[') + emsg(_(e_invarg)); + else if (expr[0] == '.') + emsg(_("E985: .= is not supported with script version 2")); + else if (!ends_excmd(*arg)) + // ":let var1 var2" + arg = list_arg_vars(eap, arg, &first); + else if (!eap->skip) + { + // ":let" + list_glob_vars(&first); + list_buf_vars(&first); + list_win_vars(&first); + list_tab_vars(&first); + list_script_vars(&first); + list_func_vars(&first); + list_vim_vars(&first); + } + eap->nextcmd = check_nextcmd(arg); + } + else if (expr[0] == '=' && expr[1] == '<' && expr[2] == '<') + { + list_T *l; + + // HERE document + l = heredoc_get(eap, expr + 3); + if (l != NULL) + { + rettv_list_set(&rettv, l); + op[0] = '='; + op[1] = NUL; + (void)ex_let_vars(eap->arg, &rettv, FALSE, semicolon, var_count, + is_const, op); + clear_tv(&rettv); + } + } + else + { + op[0] = '='; + op[1] = NUL; + if (*expr != '=') + { + if (vim_strchr((char_u *)"+-*/%.", *expr) != NULL) + { + op[0] = *expr; // +=, -=, *=, /=, %= or .= + if (expr[0] == '.' && expr[1] == '.') // ..= + ++expr; + } + expr = skipwhite(expr + 2); + } + else + expr = skipwhite(expr + 1); + + if (eap->skip) + ++emsg_skip; + i = eval0(expr, &rettv, &eap->nextcmd, !eap->skip); + if (eap->skip) + { + if (i != FAIL) + clear_tv(&rettv); + --emsg_skip; + } + else if (i != FAIL) + { + (void)ex_let_vars(eap->arg, &rettv, FALSE, semicolon, var_count, + is_const, op); + clear_tv(&rettv); + } + } + } + + /* + * Assign the typevalue "tv" to the variable or variables at "arg_start". + * Handles both "var" with any type and "[var, var; var]" with a list type. + * When "op" is not NULL it points to a string with characters that + * must appear after the variable(s). Use "+", "-" or "." for add, subtract + * or concatenate. + * Returns OK or FAIL; + */ + int + ex_let_vars( + char_u *arg_start, + typval_T *tv, + int copy, // copy values from "tv", don't move + int semicolon, // from skip_var_list() + int var_count, // from skip_var_list() + int is_const, // lock variables for const + char_u *op) + { + char_u *arg = arg_start; + list_T *l; + int i; + listitem_T *item; + typval_T ltv; + + if (*arg != '[') + { + // ":let var = expr" or ":for var in list" + if (ex_let_one(arg, tv, copy, is_const, op, op) == NULL) + return FAIL; + return OK; + } + + // ":let [v1, v2] = list" or ":for [v1, v2] in listlist" + if (tv->v_type != VAR_LIST || (l = tv->vval.v_list) == NULL) + { + emsg(_(e_listreq)); + return FAIL; + } + + i = list_len(l); + if (semicolon == 0 && var_count < i) + { + emsg(_("E687: Less targets than List items")); + return FAIL; + } + if (var_count - semicolon > i) + { + emsg(_("E688: More targets than List items")); + return FAIL; + } + + item = l->lv_first; + while (*arg != ']') + { + arg = skipwhite(arg + 1); + arg = ex_let_one(arg, &item->li_tv, TRUE, is_const, + (char_u *)",;]", op); + item = item->li_next; + if (arg == NULL) + return FAIL; + + arg = skipwhite(arg); + if (*arg == ';') + { + // Put the rest of the list (may be empty) in the var after ';'. + // Create a new list for this. + l = list_alloc(); + if (l == NULL) + return FAIL; + while (item != NULL) + { + list_append_tv(l, &item->li_tv); + item = item->li_next; + } + + ltv.v_type = VAR_LIST; + ltv.v_lock = 0; + ltv.vval.v_list = l; + l->lv_refcount = 1; + + arg = ex_let_one(skipwhite(arg + 1), <v, FALSE, is_const, + (char_u *)"]", op); + clear_tv(<v); + if (arg == NULL) + return FAIL; + break; + } + else if (*arg != ',' && *arg != ']') + { + internal_error("ex_let_vars()"); + return FAIL; + } + } + + return OK; + } + + /* + * Skip over assignable variable "var" or list of variables "[var, var]". + * Used for ":let varvar = expr" and ":for varvar in expr". + * For "[var, var]" increment "*var_count" for each variable. + * for "[var, var; var]" set "semicolon". + * Return NULL for an error. + */ + char_u * + skip_var_list( + char_u *arg, + int *var_count, + int *semicolon) + { + char_u *p, *s; + + if (*arg == '[') + { + // "[var, var]": find the matching ']'. + p = arg; + for (;;) + { + p = skipwhite(p + 1); // skip whites after '[', ';' or ',' + s = skip_var_one(p); + if (s == p) + { + semsg(_(e_invarg2), p); + return NULL; + } + ++*var_count; + + p = skipwhite(s); + if (*p == ']') + break; + else if (*p == ';') + { + if (*semicolon == 1) + { + emsg(_("Double ; in list of variables")); + return NULL; + } + *semicolon = 1; + } + else if (*p != ',') + { + semsg(_(e_invarg2), p); + return NULL; + } + } + return p + 1; + } + else + return skip_var_one(arg); + } + + /* + * Skip one (assignable) variable name, including @r, $VAR, &option, d.key, + * l[idx]. + */ + static char_u * + skip_var_one(char_u *arg) + { + if (*arg == '@' && arg[1] != NUL) + return arg + 2; + return find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg, + NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); + } + + /* + * List variables for hashtab "ht" with prefix "prefix". + * If "empty" is TRUE also list NULL strings as empty strings. + */ + void + list_hashtable_vars( + hashtab_T *ht, + char *prefix, + int empty, + int *first) + { + hashitem_T *hi; + dictitem_T *di; + int todo; + char_u buf[IOSIZE]; + + todo = (int)ht->ht_used; + for (hi = ht->ht_array; todo > 0 && !got_int; ++hi) + { + if (!HASHITEM_EMPTY(hi)) + { + --todo; + di = HI2DI(hi); + + // apply :filter /pat/ to variable name + vim_strncpy((char_u *)buf, (char_u *)prefix, IOSIZE - 1); + vim_strcat((char_u *)buf, di->di_key, IOSIZE); + if (message_filtered(buf)) + continue; + + if (empty || di->di_tv.v_type != VAR_STRING + || di->di_tv.vval.v_string != NULL) + list_one_var(di, prefix, first); + } + } + } + + /* + * List global variables. + */ + static void + list_glob_vars(int *first) + { + list_hashtable_vars(&globvarht, "", TRUE, first); + } + + /* + * List buffer variables. + */ + static void + list_buf_vars(int *first) + { + list_hashtable_vars(&curbuf->b_vars->dv_hashtab, "b:", TRUE, first); + } + + /* + * List window variables. + */ + static void + list_win_vars(int *first) + { + list_hashtable_vars(&curwin->w_vars->dv_hashtab, "w:", TRUE, first); + } + + /* + * List tab page variables. + */ + static void + list_tab_vars(int *first) + { + list_hashtable_vars(&curtab->tp_vars->dv_hashtab, "t:", TRUE, first); + } + + /* + * List variables in "arg". + */ + static char_u * + list_arg_vars(exarg_T *eap, char_u *arg, int *first) + { + int error = FALSE; + int len; + char_u *name; + char_u *name_start; + char_u *arg_subsc; + char_u *tofree; + typval_T tv; + + while (!ends_excmd(*arg) && !got_int) + { + if (error || eap->skip) + { + arg = find_name_end(arg, NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); + if (!VIM_ISWHITE(*arg) && !ends_excmd(*arg)) + { + emsg_severe = TRUE; + emsg(_(e_trailing)); + break; + } + } + else + { + // get_name_len() takes care of expanding curly braces + name_start = name = arg; + len = get_name_len(&arg, &tofree, TRUE, TRUE); + if (len <= 0) + { + // This is mainly to keep test 49 working: when expanding + // curly braces fails overrule the exception error message. + if (len < 0 && !aborting()) + { + emsg_severe = TRUE; + semsg(_(e_invarg2), arg); + break; + } + error = TRUE; + } + else + { + if (tofree != NULL) + name = tofree; + if (get_var_tv(name, len, &tv, NULL, TRUE, FALSE) == FAIL) + error = TRUE; + else + { + // handle d.key, l[idx], f(expr) + arg_subsc = arg; + if (handle_subscript(&arg, &tv, TRUE, TRUE, + name, &name) == FAIL) + error = TRUE; + else + { + if (arg == arg_subsc && len == 2 && name[1] == ':') + { + switch (*name) + { + case 'g': list_glob_vars(first); break; + case 'b': list_buf_vars(first); break; + case 'w': list_win_vars(first); break; + case 't': list_tab_vars(first); break; + case 'v': list_vim_vars(first); break; + case 's': list_script_vars(first); break; + case 'l': list_func_vars(first); break; + default: + semsg(_("E738: Can't list variables for %s"), name); + } + } + else + { + char_u numbuf[NUMBUFLEN]; + char_u *tf; + int c; + char_u *s; + + s = echo_string(&tv, &tf, numbuf, 0); + c = *arg; + *arg = NUL; + list_one_var_a("", + arg == arg_subsc ? name : name_start, + tv.v_type, + s == NULL ? (char_u *)"" : s, + first); + *arg = c; + vim_free(tf); + } + clear_tv(&tv); + } + } + } + + vim_free(tofree); + } + + arg = skipwhite(arg); + } + + return arg; + } + + /* + * Set one item of ":let var = expr" or ":let [v1, v2] = list" to its value. + * Returns a pointer to the char just after the var name. + * Returns NULL if there is an error. + */ + static char_u * + ex_let_one( + char_u *arg, // points to variable name + typval_T *tv, // value to assign to variable + int copy, // copy value from "tv" + int is_const, // lock variable for const + char_u *endchars, // valid chars after variable name or NULL + char_u *op) // "+", "-", "." or NULL + { + int c1; + char_u *name; + char_u *p; + char_u *arg_end = NULL; + int len; + int opt_flags; + char_u *tofree = NULL; + + // ":let $VAR = expr": Set environment variable. + if (*arg == '$') + { + if (is_const) + { + emsg(_("E996: Cannot lock an environment variable")); + return NULL; + } + // Find the end of the name. + ++arg; + name = arg; + len = get_env_len(&arg); + if (len == 0) + semsg(_(e_invarg2), name - 1); + else + { + if (op != NULL && vim_strchr((char_u *)"+-*/%", *op) != NULL) + semsg(_(e_letwrong), op); + else if (endchars != NULL + && vim_strchr(endchars, *skipwhite(arg)) == NULL) + emsg(_(e_letunexp)); + else if (!check_secure()) + { + c1 = name[len]; + name[len] = NUL; + p = tv_get_string_chk(tv); + if (p != NULL && op != NULL && *op == '.') + { + int mustfree = FALSE; + char_u *s = vim_getenv(name, &mustfree); + + if (s != NULL) + { + p = tofree = concat_str(s, p); + if (mustfree) + vim_free(s); + } + } + if (p != NULL) + { + vim_setenv(name, p); + if (STRICMP(name, "HOME") == 0) + init_homedir(); + else if (didset_vim && STRICMP(name, "VIM") == 0) + didset_vim = FALSE; + else if (didset_vimruntime + && STRICMP(name, "VIMRUNTIME") == 0) + didset_vimruntime = FALSE; + arg_end = arg; + } + name[len] = c1; + vim_free(tofree); + } + } + } + + // ":let &option = expr": Set option value. + // ":let &l:option = expr": Set local option value. + // ":let &g:option = expr": Set global option value. + else if (*arg == '&') + { + if (is_const) + { + emsg(_("E996: Cannot lock an option")); + return NULL; + } + // Find the end of the name. + p = find_option_end(&arg, &opt_flags); + if (p == NULL || (endchars != NULL + && vim_strchr(endchars, *skipwhite(p)) == NULL)) + emsg(_(e_letunexp)); + else + { + long n; + int opt_type; + long numval; + char_u *stringval = NULL; + char_u *s; + + c1 = *p; + *p = NUL; + + n = (long)tv_get_number(tv); + s = tv_get_string_chk(tv); // != NULL if number or string + if (s != NULL && op != NULL && *op != '=') + { + opt_type = get_option_value(arg, &numval, + &stringval, opt_flags); + if ((opt_type == 1 && *op == '.') + || (opt_type == 0 && *op != '.')) + { + semsg(_(e_letwrong), op); + s = NULL; // don't set the value + } + else + { + if (opt_type == 1) // number + { + switch (*op) + { + case '+': n = numval + n; break; + case '-': n = numval - n; break; + case '*': n = numval * n; break; + case '/': n = (long)num_divide(numval, n); break; + case '%': n = (long)num_modulus(numval, n); break; + } + } + else if (opt_type == 0 && stringval != NULL) // string + { + s = concat_str(stringval, s); + vim_free(stringval); + stringval = s; + } + } + } + if (s != NULL) + { + set_option_value(arg, n, s, opt_flags); + arg_end = p; + } + *p = c1; + vim_free(stringval); + } + } + + // ":let @r = expr": Set register contents. + else if (*arg == '@') + { + if (is_const) + { + emsg(_("E996: Cannot lock a register")); + return NULL; + } + ++arg; + if (op != NULL && vim_strchr((char_u *)"+-*/%", *op) != NULL) + semsg(_(e_letwrong), op); + else if (endchars != NULL + && vim_strchr(endchars, *skipwhite(arg + 1)) == NULL) + emsg(_(e_letunexp)); + else + { + char_u *ptofree = NULL; + char_u *s; + + p = tv_get_string_chk(tv); + if (p != NULL && op != NULL && *op == '.') + { + s = get_reg_contents(*arg == '@' ? '"' : *arg, GREG_EXPR_SRC); + if (s != NULL) + { + p = ptofree = concat_str(s, p); + vim_free(s); + } + } + if (p != NULL) + { + write_reg_contents(*arg == '@' ? '"' : *arg, p, -1, FALSE); + arg_end = arg + 1; + } + vim_free(ptofree); + } + } + + // ":let var = expr": Set internal variable. + // ":let {expr} = expr": Idem, name made with curly braces + else if (eval_isnamec1(*arg) || *arg == '{') + { + lval_T lv; + + p = get_lval(arg, tv, &lv, FALSE, FALSE, 0, FNE_CHECK_START); + if (p != NULL && lv.ll_name != NULL) + { + if (endchars != NULL && vim_strchr(endchars, *skipwhite(p)) == NULL) + emsg(_(e_letunexp)); + else + { + set_var_lval(&lv, p, tv, copy, is_const, op); + arg_end = p; + } + } + clear_lval(&lv); + } + + else + semsg(_(e_invarg2), arg); + + return arg_end; + } + + /* + * ":unlet[!] var1 ... " command. + */ + void + ex_unlet(exarg_T *eap) + { + ex_unletlock(eap, eap->arg, 0); + } + + /* + * ":lockvar" and ":unlockvar" commands + */ + void + ex_lockvar(exarg_T *eap) + { + char_u *arg = eap->arg; + int deep = 2; + + if (eap->forceit) + deep = -1; + else if (vim_isdigit(*arg)) + { + deep = getdigits(&arg); + arg = skipwhite(arg); + } + + ex_unletlock(eap, arg, deep); + } + + /* + * ":unlet", ":lockvar" and ":unlockvar" are quite similar. + */ + static void + ex_unletlock( + exarg_T *eap, + char_u *argstart, + int deep) + { + char_u *arg = argstart; + char_u *name_end; + int error = FALSE; + lval_T lv; + + do + { + if (*arg == '$') + { + char_u *name = ++arg; + + if (get_env_len(&arg) == 0) + { + semsg(_(e_invarg2), name - 1); + return; + } + vim_unsetenv(name); + arg = skipwhite(arg); + continue; + } + + // Parse the name and find the end. + name_end = get_lval(arg, NULL, &lv, TRUE, eap->skip || error, 0, + FNE_CHECK_START); + if (lv.ll_name == NULL) + error = TRUE; // error but continue parsing + if (name_end == NULL || (!VIM_ISWHITE(*name_end) + && !ends_excmd(*name_end))) + { + if (name_end != NULL) + { + emsg_severe = TRUE; + emsg(_(e_trailing)); + } + if (!(eap->skip || error)) + clear_lval(&lv); + break; + } + + if (!error && !eap->skip) + { + if (eap->cmdidx == CMD_unlet) + { + if (do_unlet_var(&lv, name_end, eap->forceit) == FAIL) + error = TRUE; + } + else + { + if (do_lock_var(&lv, name_end, deep, + eap->cmdidx == CMD_lockvar) == FAIL) + error = TRUE; + } + } + + if (!eap->skip) + clear_lval(&lv); + + arg = skipwhite(name_end); + } while (!ends_excmd(*arg)); + + eap->nextcmd = check_nextcmd(arg); + } + + static int + do_unlet_var( + lval_T *lp, + char_u *name_end, + int forceit) + { + int ret = OK; + int cc; + + if (lp->ll_tv == NULL) + { + cc = *name_end; + *name_end = NUL; + + // Normal name or expanded name. + if (do_unlet(lp->ll_name, forceit) == FAIL) + ret = FAIL; + *name_end = cc; + } + else if ((lp->ll_list != NULL + && var_check_lock(lp->ll_list->lv_lock, lp->ll_name, FALSE)) + || (lp->ll_dict != NULL + && var_check_lock(lp->ll_dict->dv_lock, lp->ll_name, FALSE))) + return FAIL; + else if (lp->ll_range) + { + listitem_T *li; + listitem_T *ll_li = lp->ll_li; + int ll_n1 = lp->ll_n1; + + while (ll_li != NULL && (lp->ll_empty2 || lp->ll_n2 >= ll_n1)) + { + li = ll_li->li_next; + if (var_check_lock(ll_li->li_tv.v_lock, lp->ll_name, FALSE)) + return FAIL; + ll_li = li; + ++ll_n1; + } + + // Delete a range of List items. + while (lp->ll_li != NULL && (lp->ll_empty2 || lp->ll_n2 >= lp->ll_n1)) + { + li = lp->ll_li->li_next; + listitem_remove(lp->ll_list, lp->ll_li); + lp->ll_li = li; + ++lp->ll_n1; + } + } + else + { + if (lp->ll_list != NULL) + // unlet a List item. + listitem_remove(lp->ll_list, lp->ll_li); + else + // unlet a Dictionary item. + dictitem_remove(lp->ll_dict, lp->ll_di); + } + + return ret; + } + + /* + * "unlet" a variable. Return OK if it existed, FAIL if not. + * When "forceit" is TRUE don't complain if the variable doesn't exist. + */ + int + do_unlet(char_u *name, int forceit) + { + hashtab_T *ht; + hashitem_T *hi; + char_u *varname; + dict_T *d; + dictitem_T *di; + + ht = find_var_ht(name, &varname); + if (ht != NULL && *varname != NUL) + { + d = get_current_funccal_dict(ht); + if (d == NULL) + { + if (ht == &globvarht) + d = &globvardict; + else if (is_compatht(ht)) + d = &vimvardict; + else + { + di = find_var_in_ht(ht, *name, (char_u *)"", FALSE); + d = di == NULL ? NULL : di->di_tv.vval.v_dict; + } + if (d == NULL) + { + internal_error("do_unlet()"); + return FAIL; + } + } + hi = hash_find(ht, varname); + if (HASHITEM_EMPTY(hi)) + hi = find_hi_in_scoped_ht(name, &ht); + if (hi != NULL && !HASHITEM_EMPTY(hi)) + { + di = HI2DI(hi); + if (var_check_fixed(di->di_flags, name, FALSE) + || var_check_ro(di->di_flags, name, FALSE) + || var_check_lock(d->dv_lock, name, FALSE)) + return FAIL; + + delete_var(ht, hi); + return OK; + } + } + if (forceit) + return OK; + semsg(_("E108: No such variable: \"%s\""), name); + return FAIL; + } + + /* + * Lock or unlock variable indicated by "lp". + * "deep" is the levels to go (-1 for unlimited); + * "lock" is TRUE for ":lockvar", FALSE for ":unlockvar". + */ + static int + do_lock_var( + lval_T *lp, + char_u *name_end, + int deep, + int lock) + { + int ret = OK; + int cc; + dictitem_T *di; + + if (deep == 0) // nothing to do + return OK; + + if (lp->ll_tv == NULL) + { + cc = *name_end; + *name_end = NUL; + + // Normal name or expanded name. + di = find_var(lp->ll_name, NULL, TRUE); + if (di == NULL) + ret = FAIL; + else if ((di->di_flags & DI_FLAGS_FIX) + && di->di_tv.v_type != VAR_DICT + && di->di_tv.v_type != VAR_LIST) + // For historic reasons this error is not given for a list or dict. + // E.g., the b: dict could be locked/unlocked. + semsg(_("E940: Cannot lock or unlock variable %s"), lp->ll_name); + else + { + if (lock) + di->di_flags |= DI_FLAGS_LOCK; + else + di->di_flags &= ~DI_FLAGS_LOCK; + item_lock(&di->di_tv, deep, lock); + } + *name_end = cc; + } + else if (lp->ll_range) + { + listitem_T *li = lp->ll_li; + + // (un)lock a range of List items. + while (li != NULL && (lp->ll_empty2 || lp->ll_n2 >= lp->ll_n1)) + { + item_lock(&li->li_tv, deep, lock); + li = li->li_next; + ++lp->ll_n1; + } + } + else if (lp->ll_list != NULL) + // (un)lock a List item. + item_lock(&lp->ll_li->li_tv, deep, lock); + else + // (un)lock a Dictionary item. + item_lock(&lp->ll_di->di_tv, deep, lock); + + return ret; + } + + /* + * Lock or unlock an item. "deep" is nr of levels to go. + */ + static void + item_lock(typval_T *tv, int deep, int lock) + { + static int recurse = 0; + list_T *l; + listitem_T *li; + dict_T *d; + blob_T *b; + hashitem_T *hi; + int todo; + + if (recurse >= DICT_MAXNEST) + { + emsg(_("E743: variable nested too deep for (un)lock")); + return; + } + if (deep == 0) + return; + ++recurse; + + // lock/unlock the item itself + if (lock) + tv->v_lock |= VAR_LOCKED; + else + tv->v_lock &= ~VAR_LOCKED; + + switch (tv->v_type) + { + case VAR_UNKNOWN: + case VAR_NUMBER: + case VAR_STRING: + case VAR_FUNC: + case VAR_PARTIAL: + case VAR_FLOAT: + case VAR_SPECIAL: + case VAR_JOB: + case VAR_CHANNEL: + break; + + case VAR_BLOB: + if ((b = tv->vval.v_blob) != NULL) + { + if (lock) + b->bv_lock |= VAR_LOCKED; + else + b->bv_lock &= ~VAR_LOCKED; + } + break; + case VAR_LIST: + if ((l = tv->vval.v_list) != NULL) + { + if (lock) + l->lv_lock |= VAR_LOCKED; + else + l->lv_lock &= ~VAR_LOCKED; + if (deep < 0 || deep > 1) + // recursive: lock/unlock the items the List contains + for (li = l->lv_first; li != NULL; li = li->li_next) + item_lock(&li->li_tv, deep - 1, lock); + } + break; + case VAR_DICT: + if ((d = tv->vval.v_dict) != NULL) + { + if (lock) + d->dv_lock |= VAR_LOCKED; + else + d->dv_lock &= ~VAR_LOCKED; + if (deep < 0 || deep > 1) + { + // recursive: lock/unlock the items the List contains + todo = (int)d->dv_hashtab.ht_used; + for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) + { + if (!HASHITEM_EMPTY(hi)) + { + --todo; + item_lock(&HI2DI(hi)->di_tv, deep - 1, lock); + } + } + } + } + } + --recurse; + } + + /* + * Get the value of internal variable "name". + * Return OK or FAIL. If OK is returned "rettv" must be cleared. + */ + int + get_var_tv( + char_u *name, + int len, // length of "name" + typval_T *rettv, // NULL when only checking existence + dictitem_T **dip, // non-NULL when typval's dict item is needed + int verbose, // may give error message + int no_autoload) // do not use script autoloading + { + int ret = OK; + typval_T *tv = NULL; + dictitem_T *v; + int cc; + + // truncate the name, so that we can use strcmp() + cc = name[len]; + name[len] = NUL; + + // Check for user-defined variables. + v = find_var(name, NULL, no_autoload); + if (v != NULL) + { + tv = &v->di_tv; + if (dip != NULL) + *dip = v; + } + + if (tv == NULL) + { + if (rettv != NULL && verbose) + semsg(_(e_undefvar), name); + ret = FAIL; + } + else if (rettv != NULL) + copy_tv(tv, rettv); + + name[len] = cc; + + return ret; + } + + /* + * Get the string value of a (global/local) variable. + * Note: see tv_get_string() for how long the pointer remains valid. + * Returns NULL when it doesn't exist. + */ + char_u * + get_var_value(char_u *name) + { + dictitem_T *v; + + v = find_var(name, NULL, FALSE); + if (v == NULL) + return NULL; + return tv_get_string(&v->di_tv); + } + + /* + * Clean up a list of internal variables. + * Frees all allocated variables and the value they contain. + * Clears hashtab "ht", does not free it. + */ + void + vars_clear(hashtab_T *ht) + { + vars_clear_ext(ht, TRUE); + } + + /* + * Like vars_clear(), but only free the value if "free_val" is TRUE. + */ + void + vars_clear_ext(hashtab_T *ht, int free_val) + { + int todo; + hashitem_T *hi; + dictitem_T *v; + + hash_lock(ht); + todo = (int)ht->ht_used; + for (hi = ht->ht_array; todo > 0; ++hi) + { + if (!HASHITEM_EMPTY(hi)) + { + --todo; + + // Free the variable. Don't remove it from the hashtab, + // ht_array might change then. hash_clear() takes care of it + // later. + v = HI2DI(hi); + if (free_val) + clear_tv(&v->di_tv); + if (v->di_flags & DI_FLAGS_ALLOC) + vim_free(v); + } + } + hash_clear(ht); + ht->ht_used = 0; + } + + /* + * Delete a variable from hashtab "ht" at item "hi". + * Clear the variable value and free the dictitem. + */ + void + delete_var(hashtab_T *ht, hashitem_T *hi) + { + dictitem_T *di = HI2DI(hi); + + hash_remove(ht, hi); + clear_tv(&di->di_tv); + vim_free(di); + } + + /* + * List the value of one internal variable. + */ + static void + list_one_var(dictitem_T *v, char *prefix, int *first) + { + char_u *tofree; + char_u *s; + char_u numbuf[NUMBUFLEN]; + + s = echo_string(&v->di_tv, &tofree, numbuf, get_copyID()); + list_one_var_a(prefix, v->di_key, v->di_tv.v_type, + s == NULL ? (char_u *)"" : s, first); + vim_free(tofree); + } + + static void + list_one_var_a( + char *prefix, + char_u *name, + int type, + char_u *string, + int *first) // when TRUE clear rest of screen and set to FALSE + { + // don't use msg() or msg_attr() to avoid overwriting "v:statusmsg" + msg_start(); + msg_puts(prefix); + if (name != NULL) // "a:" vars don't have a name stored + msg_puts((char *)name); + msg_putchar(' '); + msg_advance(22); + if (type == VAR_NUMBER) + msg_putchar('#'); + else if (type == VAR_FUNC || type == VAR_PARTIAL) + msg_putchar('*'); + else if (type == VAR_LIST) + { + msg_putchar('['); + if (*string == '[') + ++string; + } + else if (type == VAR_DICT) + { + msg_putchar('{'); + if (*string == '{') + ++string; + } + else + msg_putchar(' '); + + msg_outtrans(string); + + if (type == VAR_FUNC || type == VAR_PARTIAL) + msg_puts("()"); + if (*first) + { + msg_clr_eos(); + *first = FALSE; + } + } + + /* + * Set variable "name" to value in "tv". + * If the variable already exists, the value is updated. + * Otherwise the variable is created. + */ + void + set_var( + char_u *name, + typval_T *tv, + int copy) // make copy of value in "tv" + { + set_var_const(name, tv, copy, FALSE); + } + + /* + * Set variable "name" to value in "tv". + * If the variable already exists and "is_const" is FALSE the value is updated. + * Otherwise the variable is created. + */ + void + set_var_const( + char_u *name, + typval_T *tv, + int copy, // make copy of value in "tv" + int is_const) // disallow to modify existing variable + { + dictitem_T *v; + char_u *varname; + hashtab_T *ht; + + ht = find_var_ht(name, &varname); + if (ht == NULL || *varname == NUL) + { + semsg(_(e_illvar), name); + return; + } + v = find_var_in_ht(ht, 0, varname, TRUE); + + // Search in parent scope which is possible to reference from lambda + if (v == NULL) + v = find_var_in_scoped_ht(name, TRUE); + + if ((tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL) + && var_check_func_name(name, v == NULL)) + return; + + if (v != NULL) + { + if (is_const) + { + emsg(_(e_cannot_mod)); + return; + } + + // existing variable, need to clear the value + if (var_check_ro(v->di_flags, name, FALSE) + || var_check_lock(v->di_tv.v_lock, name, FALSE)) + return; + + // Handle setting internal v: variables separately where needed to + // prevent changing the type. + if (is_vimvarht(ht)) + { + if (v->di_tv.v_type == VAR_STRING) + { + VIM_CLEAR(v->di_tv.vval.v_string); + if (copy || tv->v_type != VAR_STRING) + { + char_u *val = tv_get_string(tv); + + // Careful: when assigning to v:errmsg and tv_get_string() + // causes an error message the variable will alrady be set. + if (v->di_tv.vval.v_string == NULL) + v->di_tv.vval.v_string = vim_strsave(val); + } + else + { + // Take over the string to avoid an extra alloc/free. + v->di_tv.vval.v_string = tv->vval.v_string; + tv->vval.v_string = NULL; + } + return; + } + else if (v->di_tv.v_type == VAR_NUMBER) + { + v->di_tv.vval.v_number = tv_get_number(tv); + if (STRCMP(varname, "searchforward") == 0) + set_search_direction(v->di_tv.vval.v_number ? '/' : '?'); + #ifdef FEAT_SEARCH_EXTRA + else if (STRCMP(varname, "hlsearch") == 0) + { + no_hlsearch = !v->di_tv.vval.v_number; + redraw_all_later(SOME_VALID); + } + #endif + return; + } + else if (v->di_tv.v_type != tv->v_type) + { + semsg(_("E963: setting %s to value with wrong type"), name); + return; + } + } + + clear_tv(&v->di_tv); + } + else // add a new variable + { + // Can't add "v:" or "a:" variable. + if (is_vimvarht(ht) || ht == get_funccal_args_ht()) + { + semsg(_(e_illvar), name); + return; + } + + // Make sure the variable name is valid. + if (!valid_varname(varname)) + return; + + v = alloc(sizeof(dictitem_T) + STRLEN(varname)); + if (v == NULL) + return; + STRCPY(v->di_key, varname); + if (hash_add(ht, DI2HIKEY(v)) == FAIL) + { + vim_free(v); + return; + } + v->di_flags = DI_FLAGS_ALLOC; + if (is_const) + v->di_flags |= DI_FLAGS_LOCK; + } + + if (copy || tv->v_type == VAR_NUMBER || tv->v_type == VAR_FLOAT) + copy_tv(tv, &v->di_tv); + else + { + v->di_tv = *tv; + v->di_tv.v_lock = 0; + init_tv(tv); + } + + if (is_const) + v->di_tv.v_lock |= VAR_LOCKED; + } + + /* + * Return TRUE if di_flags "flags" indicates variable "name" is read-only. + * Also give an error message. + */ + int + var_check_ro(int flags, char_u *name, int use_gettext) + { + if (flags & DI_FLAGS_RO) + { + semsg(_(e_readonlyvar), use_gettext ? (char_u *)_(name) : name); + return TRUE; + } + if ((flags & DI_FLAGS_RO_SBX) && sandbox) + { + semsg(_(e_readonlysbx), use_gettext ? (char_u *)_(name) : name); + return TRUE; + } + return FALSE; + } + + /* + * Return TRUE if di_flags "flags" indicates variable "name" is fixed. + * Also give an error message. + */ + int + var_check_fixed(int flags, char_u *name, int use_gettext) + { + if (flags & DI_FLAGS_FIX) + { + semsg(_("E795: Cannot delete variable %s"), + use_gettext ? (char_u *)_(name) : name); + return TRUE; + } + return FALSE; + } + + /* + * Check if a funcref is assigned to a valid variable name. + * Return TRUE and give an error if not. + */ + int + var_check_func_name( + char_u *name, // points to start of variable name + int new_var) // TRUE when creating the variable + { + // Allow for w: b: s: and t:. + if (!(vim_strchr((char_u *)"wbst", name[0]) != NULL && name[1] == ':') + && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':') + ? name[2] : name[0])) + { + semsg(_("E704: Funcref variable name must start with a capital: %s"), + name); + return TRUE; + } + // Don't allow hiding a function. When "v" is not NULL we might be + // assigning another function to the same var, the type is checked + // below. + if (new_var && function_exists(name, FALSE)) + { + semsg(_("E705: Variable name conflicts with existing function: %s"), + name); + return TRUE; + } + return FALSE; + } + + /* + * Return TRUE if "flags" indicates variable "name" is locked (immutable). + * Also give an error message, using "name" or _("name") when use_gettext is + * TRUE. + */ + int + var_check_lock(int lock, char_u *name, int use_gettext) + { + if (lock & VAR_LOCKED) + { + semsg(_("E741: Value is locked: %s"), + name == NULL ? (char_u *)_("Unknown") + : use_gettext ? (char_u *)_(name) + : name); + return TRUE; + } + if (lock & VAR_FIXED) + { + semsg(_("E742: Cannot change value of %s"), + name == NULL ? (char_u *)_("Unknown") + : use_gettext ? (char_u *)_(name) + : name); + return TRUE; + } + return FALSE; + } + + /* + * Check if a variable name is valid. + * Return FALSE and give an error if not. + */ + int + valid_varname(char_u *varname) + { + char_u *p; + + for (p = varname; *p != NUL; ++p) + if (!eval_isnamec1(*p) && (p == varname || !VIM_ISDIGIT(*p)) + && *p != AUTOLOAD_CHAR) + { + semsg(_(e_illvar), varname); + return FALSE; + } + return TRUE; + } + + /* + * getwinvar() and gettabwinvar() + */ + static void + getwinvar( + typval_T *argvars, + typval_T *rettv, + int off) // 1 for gettabwinvar() + { + win_T *win; + char_u *varname; + dictitem_T *v; + tabpage_T *tp = NULL; + int done = FALSE; + win_T *oldcurwin; + tabpage_T *oldtabpage; + int need_switch_win; + + if (off == 1) + tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL)); + else + tp = curtab; + win = find_win_by_nr(&argvars[off], tp); + varname = tv_get_string_chk(&argvars[off + 1]); + ++emsg_off; + + rettv->v_type = VAR_STRING; + rettv->vval.v_string = NULL; + + if (win != NULL && varname != NULL) + { + // Set curwin to be our win, temporarily. Also set the tabpage, + // otherwise the window is not valid. Only do this when needed, + // autocommands get blocked. + need_switch_win = !(tp == curtab && win == curwin); + if (!need_switch_win + || switch_win(&oldcurwin, &oldtabpage, win, tp, TRUE) == OK) + { + if (*varname == '&') + { + if (varname[1] == NUL) + { + // get all window-local options in a dict + dict_T *opts = get_winbuf_options(FALSE); + + if (opts != NULL) + { + rettv_dict_set(rettv, opts); + done = TRUE; + } + } + else if (get_option_tv(&varname, rettv, 1) == OK) + // window-local-option + done = TRUE; + } + else + { + // Look up the variable. + // Let getwinvar({nr}, "") return the "w:" dictionary. + v = find_var_in_ht(&win->w_vars->dv_hashtab, 'w', + varname, FALSE); + if (v != NULL) + { + copy_tv(&v->di_tv, rettv); + done = TRUE; + } + } + } + + if (need_switch_win) + // restore previous notion of curwin + restore_win(oldcurwin, oldtabpage, TRUE); + } + + if (!done && argvars[off + 2].v_type != VAR_UNKNOWN) + // use the default return value + copy_tv(&argvars[off + 2], rettv); + + --emsg_off; + } + + /* + * "setwinvar()" and "settabwinvar()" functions + */ + static void + setwinvar(typval_T *argvars, typval_T *rettv UNUSED, int off) + { + win_T *win; + win_T *save_curwin; + tabpage_T *save_curtab; + int need_switch_win; + char_u *varname, *winvarname; + typval_T *varp; + char_u nbuf[NUMBUFLEN]; + tabpage_T *tp = NULL; + + if (check_secure()) + return; + + if (off == 1) + tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL)); + else + tp = curtab; + win = find_win_by_nr(&argvars[off], tp); + varname = tv_get_string_chk(&argvars[off + 1]); + varp = &argvars[off + 2]; + + if (win != NULL && varname != NULL && varp != NULL) + { + need_switch_win = !(tp == curtab && win == curwin); + if (!need_switch_win + || switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == OK) + { + if (*varname == '&') + { + long numval; + char_u *strval; + int error = FALSE; + + ++varname; + numval = (long)tv_get_number_chk(varp, &error); + strval = tv_get_string_buf_chk(varp, nbuf); + if (!error && strval != NULL) + set_option_value(varname, numval, strval, OPT_LOCAL); + } + else + { + winvarname = alloc(STRLEN(varname) + 3); + if (winvarname != NULL) + { + STRCPY(winvarname, "w:"); + STRCPY(winvarname + 2, varname); + set_var(winvarname, varp, TRUE); + vim_free(winvarname); + } + } + } + if (need_switch_win) + restore_win(save_curwin, save_curtab, TRUE); + } + } + + int + var_exists(char_u *var) + { + char_u *name; + char_u *tofree; + typval_T tv; + int len = 0; + int n = FALSE; + + // get_name_len() takes care of expanding curly braces + name = var; + len = get_name_len(&var, &tofree, TRUE, FALSE); + if (len > 0) + { + if (tofree != NULL) + name = tofree; + n = (get_var_tv(name, len, &tv, NULL, FALSE, TRUE) == OK); + if (n) + { + // handle d.key, l[idx], f(expr) + n = (handle_subscript(&var, &tv, TRUE, FALSE, name, &name) == OK); + if (n) + clear_tv(&tv); + } + } + if (*var != NUL) + n = FALSE; + + vim_free(tofree); + return n; + } + + /* + * "gettabvar()" function + */ + void + f_gettabvar(typval_T *argvars, typval_T *rettv) + { + win_T *oldcurwin; + tabpage_T *tp, *oldtabpage; + dictitem_T *v; + char_u *varname; + int done = FALSE; + + rettv->v_type = VAR_STRING; + rettv->vval.v_string = NULL; + + varname = tv_get_string_chk(&argvars[1]); + tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL)); + if (tp != NULL && varname != NULL) + { + // Set tp to be our tabpage, temporarily. Also set the window to the + // first window in the tabpage, otherwise the window is not valid. + if (switch_win(&oldcurwin, &oldtabpage, + tp == curtab || tp->tp_firstwin == NULL ? firstwin + : tp->tp_firstwin, tp, TRUE) == OK) + { + // look up the variable + // Let gettabvar({nr}, "") return the "t:" dictionary. + v = find_var_in_ht(&tp->tp_vars->dv_hashtab, 't', varname, FALSE); + if (v != NULL) + { + copy_tv(&v->di_tv, rettv); + done = TRUE; + } + } + + // restore previous notion of curwin + restore_win(oldcurwin, oldtabpage, TRUE); + } + + if (!done && argvars[2].v_type != VAR_UNKNOWN) + copy_tv(&argvars[2], rettv); + } + + /* + * "gettabwinvar()" function + */ + void + f_gettabwinvar(typval_T *argvars, typval_T *rettv) + { + getwinvar(argvars, rettv, 1); + } + + /* + * "getwinvar()" function + */ + void + f_getwinvar(typval_T *argvars, typval_T *rettv) + { + getwinvar(argvars, rettv, 0); + } + + /* + * "settabvar()" function + */ + void + f_settabvar(typval_T *argvars, typval_T *rettv) + { + tabpage_T *save_curtab; + tabpage_T *tp; + char_u *varname, *tabvarname; + typval_T *varp; + + rettv->vval.v_number = 0; + + if (check_secure()) + return; + + tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL)); + varname = tv_get_string_chk(&argvars[1]); + varp = &argvars[2]; + + if (varname != NULL && varp != NULL && tp != NULL) + { + save_curtab = curtab; + goto_tabpage_tp(tp, FALSE, FALSE); + + tabvarname = alloc(STRLEN(varname) + 3); + if (tabvarname != NULL) + { + STRCPY(tabvarname, "t:"); + STRCPY(tabvarname + 2, varname); + set_var(tabvarname, varp, TRUE); + vim_free(tabvarname); + } + + // Restore current tabpage + if (valid_tabpage(save_curtab)) + goto_tabpage_tp(save_curtab, FALSE, FALSE); + } + } + + /* + * "settabwinvar()" function + */ + void + f_settabwinvar(typval_T *argvars, typval_T *rettv) + { + setwinvar(argvars, rettv, 1); + } + + /* + * "setwinvar()" function + */ + void + f_setwinvar(typval_T *argvars, typval_T *rettv) + { + setwinvar(argvars, rettv, 0); + } + + #endif // FEAT_EVAL *** ../vim-8.1.1932/src/globals.h 2019-08-24 20:54:15.975845584 +0200 --- src/globals.h 2019-08-27 22:37:44.277253720 +0200 *************** *** 1547,1552 **** --- 1547,1556 ---- EXTERN char e_re_corr[] INIT(= N_("E44: Corrupted regexp program")); EXTERN char e_readonly[] INIT(= N_("E45: 'readonly' option is set (add ! to override)")); #ifdef FEAT_EVAL + EXTERN char e_undefvar[] INIT(= N_("E121: Undefined variable: %s")); + EXTERN char e_letwrong[] INIT(= N_("E734: Wrong variable type for %s=")); + EXTERN char e_illvar[] INIT(= N_("E461: Illegal variable name: %s")); + EXTERN char e_cannot_mod[] INIT(= N_("E995: Cannot modify existing variable")); EXTERN char e_readonlyvar[] INIT(= N_("E46: Cannot change read-only variable \"%s\"")); EXTERN char e_readonlysbx[] INIT(= N_("E794: Cannot set variable in the sandbox: \"%s\"")); EXTERN char e_emptykey[] INIT(= N_("E713: Cannot use empty key for Dictionary")); *** ../vim-8.1.1932/src/proto.h 2019-08-25 15:40:39.662739502 +0200 --- src/proto.h 2019-08-27 22:37:44.277253720 +0200 *************** *** 112,117 **** --- 112,118 ---- # ifdef FEAT_VIMINFO # include "viminfo.pro" # endif + # include "evalvars.pro" /* These prototypes cannot be produced automatically. */ int smsg(const char *, ...) *** ../vim-8.1.1932/src/proto/eval.pro 2019-08-20 20:13:40.330821936 +0200 --- src/proto/eval.pro 2019-08-27 22:41:07.016138684 +0200 *************** *** 1,4 **** --- 1,6 ---- /* eval.c */ + varnumber_T num_divide(varnumber_T n1, varnumber_T n2); + varnumber_T num_modulus(varnumber_T n1, varnumber_T n2); void eval_init(void); void eval_clear(void); void set_internal_string_var(char_u *name, char_u *value); *************** *** 17,22 **** --- 19,28 ---- char_u *eval_to_string(char_u *arg, char_u **nextcmd, int convert); char_u *eval_to_string_safe(char_u *arg, char_u **nextcmd, int use_sandbox); varnumber_T eval_to_number(char_u *expr); + void list_vim_vars(int *first); + void list_script_vars(int *first); + int is_vimvarht(hashtab_T *ht); + int is_compatht(hashtab_T *ht); void prepare_vimvar(int idx, typval_T *save_tv); void restore_vimvar(int idx, typval_T *save_tv); list_T *eval_spell_expr(char_u *badword, char_u *expr); *************** *** 27,44 **** void *call_func_retstr(char_u *func, int argc, typval_T *argv); void *call_func_retlist(char_u *func, int argc, typval_T *argv); int eval_foldexpr(char_u *arg, int *cp); - void ex_let(exarg_T *eap); - void ex_const(exarg_T *eap); - void list_hashtable_vars(hashtab_T *ht, char *prefix, int empty, int *first); char_u *get_lval(char_u *name, typval_T *rettv, lval_T *lp, int unlet, int skip, int flags, int fne_flags); void clear_lval(lval_T *lp); void *eval_for_line(char_u *arg, int *errp, char_u **nextcmdp, int skip); int next_for_item(void *fi_void, char_u *arg); void free_for_info(void *fi_void); void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx); - void ex_unlet(exarg_T *eap); - void ex_lockvar(exarg_T *eap); - int do_unlet(char_u *name, int forceit); void del_menutrans_vars(void); char_u *get_user_var_name(expand_T *xp, int idx); int pattern_match(char_u *pat, char_u *text, int ic); --- 33,45 ---- void *call_func_retstr(char_u *func, int argc, typval_T *argv); void *call_func_retlist(char_u *func, int argc, typval_T *argv); int eval_foldexpr(char_u *arg, int *cp); char_u *get_lval(char_u *name, typval_T *rettv, lval_T *lp, int unlet, int skip, int flags, int fne_flags); void clear_lval(lval_T *lp); + void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, int is_const, char_u *op); void *eval_for_line(char_u *arg, int *errp, char_u **nextcmdp, int skip); int next_for_item(void *fi_void, char_u *arg); void free_for_info(void *fi_void); void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx); void del_menutrans_vars(void); char_u *get_user_var_name(expand_T *xp, int idx); int pattern_match(char_u *pat, char_u *text, int ic); *************** *** 62,68 **** --- 63,71 ---- int string2float(char_u *text, float_T *value); pos_T *var2fpos(typval_T *varp, int dollar_lnum, int *fnum); int list2fpos(typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp); + int get_env_len(char_u **arg); int get_id_len(char_u **arg); + int get_name_len(char_u **arg, char_u **alias, int evaluate, int verbose); char_u *find_name_end(char_u *arg, char_u **expr_start, char_u **expr_end, int flags); int eval_isnamec(int c); int eval_isnamec1(int c); *************** *** 98,115 **** dictitem_T *find_var(char_u *name, hashtab_T **htp, int no_autoload); dictitem_T *find_var_in_ht(hashtab_T *ht, int htname, char_u *varname, int no_autoload); hashtab_T *find_var_ht(char_u *name, char_u **varname); - char_u *get_var_value(char_u *name); void new_script_vars(scid_T id); void init_var_dict(dict_T *dict, dictitem_T *dict_var, int scope); void unref_var_dict(dict_T *dict); - void vars_clear(hashtab_T *ht); - void vars_clear_ext(hashtab_T *ht, int free_val); - void set_var(char_u *name, typval_T *tv, int copy); - int var_check_ro(int flags, char_u *name, int use_gettext); - int var_check_fixed(int flags, char_u *name, int use_gettext); - int var_check_func_name(char_u *name, int new_var); - int var_check_lock(int lock, char_u *name, int use_gettext); - int valid_varname(char_u *varname); void copy_tv(typval_T *from, typval_T *to); int item_copy(typval_T *from, typval_T *to, int deep, int copyID); void get_user_input(typval_T *argvars, typval_T *rettv, int inputdialog, int secret); --- 101,109 ---- *************** *** 119,126 **** win_T *find_win_by_nr(typval_T *vp, tabpage_T *tp); win_T *find_win_by_nr_or_id(typval_T *vp); win_T *find_tabwin(typval_T *wvp, typval_T *tvp, tabpage_T **ptp); ! void getwinvar(typval_T *argvars, typval_T *rettv, int off); ! void setwinvar(typval_T *argvars, typval_T *rettv, int off); char_u *autoload_name(char_u *name); int script_autoload(char_u *name, int reload); void last_set_msg(sctx_T script_ctx); --- 113,119 ---- win_T *find_win_by_nr(typval_T *vp, tabpage_T *tp); win_T *find_win_by_nr_or_id(typval_T *vp); win_T *find_tabwin(typval_T *wvp, typval_T *tvp, tabpage_T **ptp); ! char_u *find_option_end(char_u **arg, int *opt_flags); char_u *autoload_name(char_u *name); int script_autoload(char_u *name, int reload); void last_set_msg(sctx_T script_ctx); *************** *** 128,134 **** void assert_error(garray_T *gap); int typval_compare(typval_T *typ1, typval_T *typ2, exptype_T type, int type_is, int ic); char_u *typval_tostring(typval_T *arg); - int var_exists(char_u *var); int modify_fname(char_u *src, int tilde_file, int *usedlen, char_u **fnamep, char_u **bufp, int *fnamelen); char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, typval_T *expr, char_u *flags); void filter_map(typval_T *argvars, typval_T *rettv, int map); --- 121,126 ---- *** ../vim-8.1.1932/src/proto/evalvars.pro 2019-08-27 22:47:03.090089307 +0200 --- src/proto/evalvars.pro 2019-08-27 22:41:11.500114155 +0200 *************** *** 0 **** --- 1,29 ---- + /* evalvars.c */ + void ex_let(exarg_T *eap); + void ex_const(exarg_T *eap); + int ex_let_vars(char_u *arg_start, typval_T *tv, int copy, int semicolon, int var_count, int is_const, char_u *op); + char_u *skip_var_list(char_u *arg, int *var_count, int *semicolon); + void list_hashtable_vars(hashtab_T *ht, char *prefix, int empty, int *first); + void ex_unlet(exarg_T *eap); + void ex_lockvar(exarg_T *eap); + int do_unlet(char_u *name, int forceit); + int get_var_tv(char_u *name, int len, typval_T *rettv, dictitem_T **dip, int verbose, int no_autoload); + char_u *get_var_value(char_u *name); + void vars_clear(hashtab_T *ht); + void vars_clear_ext(hashtab_T *ht, int free_val); + void delete_var(hashtab_T *ht, hashitem_T *hi); + void set_var(char_u *name, typval_T *tv, int copy); + void set_var_const(char_u *name, typval_T *tv, int copy, int is_const); + int var_check_ro(int flags, char_u *name, int use_gettext); + int var_check_fixed(int flags, char_u *name, int use_gettext); + int var_check_func_name(char_u *name, int new_var); + int var_check_lock(int lock, char_u *name, int use_gettext); + int valid_varname(char_u *varname); + int var_exists(char_u *var); + void f_gettabvar(typval_T *argvars, typval_T *rettv); + void f_gettabwinvar(typval_T *argvars, typval_T *rettv); + void f_getwinvar(typval_T *argvars, typval_T *rettv); + void f_settabvar(typval_T *argvars, typval_T *rettv); + void f_settabwinvar(typval_T *argvars, typval_T *rettv); + void f_setwinvar(typval_T *argvars, typval_T *rettv); + /* vim: set ft=c : */ *** ../vim-8.1.1932/src/vim.h 2019-08-23 20:58:42.020375498 +0200 --- src/vim.h 2019-08-27 22:37:44.277253720 +0200 *************** *** 2003,2008 **** --- 2003,2010 ---- #define VAR_TYPE_CHANNEL 9 #define VAR_TYPE_BLOB 10 + #define DICT_MAXNEST 100 /* maximum nesting of lists and dicts */ + #ifdef FEAT_CLIPBOARD /* VIM_ATOM_NAME is the older Vim-specific selection type for X11. Still *** ../vim-8.1.1932/src/version.c 2019-08-27 21:56:01.699592495 +0200 --- src/version.c 2019-08-27 22:47:10.494023254 +0200 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 1933, /**/ -- The difference between theory and practice, is that in theory, there is no difference between theory and practice. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///