Mercurial > vim
comparison src/evalfunc.c @ 16604:1e0a5f09fdf1 v8.1.1305
patch 8.1.1305: there is no easy way to manipulate environment variables
commit https://github.com/vim/vim/commit/691ddeefb545d8488e5a495af61caba2e57b3de9
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu May 9 14:52:41 2019 +0200
patch 8.1.1305: there is no easy way to manipulate environment variables
Problem: There is no easy way to manipulate environment variables.
Solution: Add environ(), getenv() and setenv(). (Yasuhiro Matsumoto,
closes #2875)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 09 May 2019 15:00:07 +0200 |
parents | ff3c99bd1038 |
children | 7e733046db1d |
comparison
equal
deleted
inserted
replaced
16603:83e535d7e403 | 16604:1e0a5f09fdf1 |
---|---|
135 static void f_deletebufline(typval_T *argvars, typval_T *rettv); | 135 static void f_deletebufline(typval_T *argvars, typval_T *rettv); |
136 static void f_did_filetype(typval_T *argvars, typval_T *rettv); | 136 static void f_did_filetype(typval_T *argvars, typval_T *rettv); |
137 static void f_diff_filler(typval_T *argvars, typval_T *rettv); | 137 static void f_diff_filler(typval_T *argvars, typval_T *rettv); |
138 static void f_diff_hlID(typval_T *argvars, typval_T *rettv); | 138 static void f_diff_hlID(typval_T *argvars, typval_T *rettv); |
139 static void f_empty(typval_T *argvars, typval_T *rettv); | 139 static void f_empty(typval_T *argvars, typval_T *rettv); |
140 static void f_environ(typval_T *argvars, typval_T *rettv); | |
140 static void f_escape(typval_T *argvars, typval_T *rettv); | 141 static void f_escape(typval_T *argvars, typval_T *rettv); |
141 static void f_eval(typval_T *argvars, typval_T *rettv); | 142 static void f_eval(typval_T *argvars, typval_T *rettv); |
142 static void f_eventhandler(typval_T *argvars, typval_T *rettv); | 143 static void f_eventhandler(typval_T *argvars, typval_T *rettv); |
143 static void f_executable(typval_T *argvars, typval_T *rettv); | 144 static void f_executable(typval_T *argvars, typval_T *rettv); |
144 static void f_execute(typval_T *argvars, typval_T *rettv); | 145 static void f_execute(typval_T *argvars, typval_T *rettv); |
185 #endif | 186 #endif |
186 static void f_getcmdpos(typval_T *argvars, typval_T *rettv); | 187 static void f_getcmdpos(typval_T *argvars, typval_T *rettv); |
187 static void f_getcmdtype(typval_T *argvars, typval_T *rettv); | 188 static void f_getcmdtype(typval_T *argvars, typval_T *rettv); |
188 static void f_getcmdwintype(typval_T *argvars, typval_T *rettv); | 189 static void f_getcmdwintype(typval_T *argvars, typval_T *rettv); |
189 static void f_getcwd(typval_T *argvars, typval_T *rettv); | 190 static void f_getcwd(typval_T *argvars, typval_T *rettv); |
191 static void f_getenv(typval_T *argvars, typval_T *rettv); | |
190 static void f_getfontname(typval_T *argvars, typval_T *rettv); | 192 static void f_getfontname(typval_T *argvars, typval_T *rettv); |
191 static void f_getfperm(typval_T *argvars, typval_T *rettv); | 193 static void f_getfperm(typval_T *argvars, typval_T *rettv); |
192 static void f_getfsize(typval_T *argvars, typval_T *rettv); | 194 static void f_getfsize(typval_T *argvars, typval_T *rettv); |
193 static void f_getftime(typval_T *argvars, typval_T *rettv); | 195 static void f_getftime(typval_T *argvars, typval_T *rettv); |
194 static void f_getftype(typval_T *argvars, typval_T *rettv); | 196 static void f_getftype(typval_T *argvars, typval_T *rettv); |
363 static void f_serverlist(typval_T *argvars, typval_T *rettv); | 365 static void f_serverlist(typval_T *argvars, typval_T *rettv); |
364 static void f_setbufline(typval_T *argvars, typval_T *rettv); | 366 static void f_setbufline(typval_T *argvars, typval_T *rettv); |
365 static void f_setbufvar(typval_T *argvars, typval_T *rettv); | 367 static void f_setbufvar(typval_T *argvars, typval_T *rettv); |
366 static void f_setcharsearch(typval_T *argvars, typval_T *rettv); | 368 static void f_setcharsearch(typval_T *argvars, typval_T *rettv); |
367 static void f_setcmdpos(typval_T *argvars, typval_T *rettv); | 369 static void f_setcmdpos(typval_T *argvars, typval_T *rettv); |
370 static void f_setenv(typval_T *argvars, typval_T *rettv); | |
368 static void f_setfperm(typval_T *argvars, typval_T *rettv); | 371 static void f_setfperm(typval_T *argvars, typval_T *rettv); |
369 static void f_setline(typval_T *argvars, typval_T *rettv); | 372 static void f_setline(typval_T *argvars, typval_T *rettv); |
370 static void f_setloclist(typval_T *argvars, typval_T *rettv); | 373 static void f_setloclist(typval_T *argvars, typval_T *rettv); |
371 static void f_setmatches(typval_T *argvars, typval_T *rettv); | 374 static void f_setmatches(typval_T *argvars, typval_T *rettv); |
372 static void f_setpos(typval_T *argvars, typval_T *rettv); | 375 static void f_setpos(typval_T *argvars, typval_T *rettv); |
627 {"deletebufline", 2, 3, f_deletebufline}, | 630 {"deletebufline", 2, 3, f_deletebufline}, |
628 {"did_filetype", 0, 0, f_did_filetype}, | 631 {"did_filetype", 0, 0, f_did_filetype}, |
629 {"diff_filler", 1, 1, f_diff_filler}, | 632 {"diff_filler", 1, 1, f_diff_filler}, |
630 {"diff_hlID", 2, 2, f_diff_hlID}, | 633 {"diff_hlID", 2, 2, f_diff_hlID}, |
631 {"empty", 1, 1, f_empty}, | 634 {"empty", 1, 1, f_empty}, |
635 {"environ", 0, 0, f_environ}, | |
632 {"escape", 2, 2, f_escape}, | 636 {"escape", 2, 2, f_escape}, |
633 {"eval", 1, 1, f_eval}, | 637 {"eval", 1, 1, f_eval}, |
634 {"eventhandler", 0, 0, f_eventhandler}, | 638 {"eventhandler", 0, 0, f_eventhandler}, |
635 {"executable", 1, 1, f_executable}, | 639 {"executable", 1, 1, f_executable}, |
636 {"execute", 1, 2, f_execute}, | 640 {"execute", 1, 2, f_execute}, |
679 #if defined(FEAT_CMDL_COMPL) | 683 #if defined(FEAT_CMDL_COMPL) |
680 {"getcompletion", 2, 3, f_getcompletion}, | 684 {"getcompletion", 2, 3, f_getcompletion}, |
681 #endif | 685 #endif |
682 {"getcurpos", 0, 0, f_getcurpos}, | 686 {"getcurpos", 0, 0, f_getcurpos}, |
683 {"getcwd", 0, 2, f_getcwd}, | 687 {"getcwd", 0, 2, f_getcwd}, |
688 {"getenv", 1, 1, f_getenv}, | |
684 {"getfontname", 0, 1, f_getfontname}, | 689 {"getfontname", 0, 1, f_getfontname}, |
685 {"getfperm", 1, 1, f_getfperm}, | 690 {"getfperm", 1, 1, f_getfperm}, |
686 {"getfsize", 1, 1, f_getfsize}, | 691 {"getfsize", 1, 1, f_getfsize}, |
687 {"getftime", 1, 1, f_getftime}, | 692 {"getftime", 1, 1, f_getftime}, |
688 {"getftype", 1, 1, f_getftype}, | 693 {"getftype", 1, 1, f_getftype}, |
871 {"serverlist", 0, 0, f_serverlist}, | 876 {"serverlist", 0, 0, f_serverlist}, |
872 {"setbufline", 3, 3, f_setbufline}, | 877 {"setbufline", 3, 3, f_setbufline}, |
873 {"setbufvar", 3, 3, f_setbufvar}, | 878 {"setbufvar", 3, 3, f_setbufvar}, |
874 {"setcharsearch", 1, 1, f_setcharsearch}, | 879 {"setcharsearch", 1, 1, f_setcharsearch}, |
875 {"setcmdpos", 1, 1, f_setcmdpos}, | 880 {"setcmdpos", 1, 1, f_setcmdpos}, |
881 {"setenv", 2, 2, f_setenv}, | |
876 {"setfperm", 2, 2, f_setfperm}, | 882 {"setfperm", 2, 2, f_setfperm}, |
877 {"setline", 2, 2, f_setline}, | 883 {"setline", 2, 2, f_setline}, |
878 {"setloclist", 2, 4, f_setloclist}, | 884 {"setloclist", 2, 4, f_setloclist}, |
879 {"setmatches", 1, 2, f_setmatches}, | 885 {"setmatches", 1, 2, f_setmatches}, |
880 {"setpos", 2, 2, f_setpos}, | 886 {"setpos", 2, 2, f_setpos}, |
3335 n = TRUE; | 3341 n = TRUE; |
3336 break; | 3342 break; |
3337 } | 3343 } |
3338 | 3344 |
3339 rettv->vval.v_number = n; | 3345 rettv->vval.v_number = n; |
3346 } | |
3347 | |
3348 /* | |
3349 * "environ()" function | |
3350 */ | |
3351 static void | |
3352 f_environ(typval_T *argvars UNUSED, typval_T *rettv) | |
3353 { | |
3354 #if !defined(AMIGA) | |
3355 int i = 0; | |
3356 char_u *entry, *value; | |
3357 # ifdef MSWIN | |
3358 extern wchar_t **_wenviron; | |
3359 # else | |
3360 extern char **environ; | |
3361 # endif | |
3362 | |
3363 if (rettv_dict_alloc(rettv) != OK) | |
3364 return; | |
3365 | |
3366 # ifdef MSWIN | |
3367 if (*_wenviron == NULL) | |
3368 return; | |
3369 # else | |
3370 if (*environ == NULL) | |
3371 return; | |
3372 # endif | |
3373 | |
3374 for (i = 0; ; ++i) | |
3375 { | |
3376 # ifdef MSWIN | |
3377 short_u *p; | |
3378 | |
3379 if ((p = (short_u *)_wenviron[i]) == NULL) | |
3380 return; | |
3381 entry = utf16_to_enc(p, NULL); | |
3382 # else | |
3383 if ((entry = (char_u *)environ[i]) == NULL) | |
3384 return; | |
3385 entry = vim_strsave(entry); | |
3386 # endif | |
3387 if (entry == NULL) // out of memory | |
3388 return; | |
3389 if ((value = vim_strchr(entry, '=')) == NULL) | |
3390 { | |
3391 vim_free(entry); | |
3392 continue; | |
3393 } | |
3394 *value++ = NUL; | |
3395 dict_add_string(rettv->vval.v_dict, (char *)entry, value); | |
3396 vim_free(entry); | |
3397 } | |
3398 #endif | |
3340 } | 3399 } |
3341 | 3400 |
3342 /* | 3401 /* |
3343 * "escape({string}, {chars})" function | 3402 * "escape({string}, {chars})" function |
3344 */ | 3403 */ |
5256 } | 5315 } |
5257 #ifdef BACKSLASH_IN_FILENAME | 5316 #ifdef BACKSLASH_IN_FILENAME |
5258 if (rettv->vval.v_string != NULL) | 5317 if (rettv->vval.v_string != NULL) |
5259 slash_adjust(rettv->vval.v_string); | 5318 slash_adjust(rettv->vval.v_string); |
5260 #endif | 5319 #endif |
5320 } | |
5321 | |
5322 /* | |
5323 * "getenv()" function | |
5324 */ | |
5325 static void | |
5326 f_getenv(typval_T *argvars, typval_T *rettv) | |
5327 { | |
5328 int mustfree = FALSE; | |
5329 char_u *p = vim_getenv(tv_get_string(&argvars[0]), &mustfree); | |
5330 | |
5331 if (p == NULL) | |
5332 { | |
5333 rettv->v_type = VAR_SPECIAL; | |
5334 rettv->vval.v_number = VVAL_NULL; | |
5335 return; | |
5336 } | |
5337 if (!mustfree) | |
5338 p = vim_strsave(p); | |
5339 rettv->vval.v_string = p; | |
5340 rettv->v_type = VAR_STRING; | |
5261 } | 5341 } |
5262 | 5342 |
5263 /* | 5343 /* |
5264 * "getfontname()" function | 5344 * "getfontname()" function |
5265 */ | 5345 */ |
11423 if (pos >= 0) | 11503 if (pos >= 0) |
11424 rettv->vval.v_number = set_cmdline_pos(pos); | 11504 rettv->vval.v_number = set_cmdline_pos(pos); |
11425 } | 11505 } |
11426 | 11506 |
11427 /* | 11507 /* |
11508 * "setenv()" function | |
11509 */ | |
11510 static void | |
11511 f_setenv(typval_T *argvars, typval_T *rettv UNUSED) | |
11512 { | |
11513 char_u namebuf[NUMBUFLEN]; | |
11514 char_u valbuf[NUMBUFLEN]; | |
11515 char_u *name = tv_get_string_buf(&argvars[0], namebuf); | |
11516 | |
11517 if (argvars[1].v_type == VAR_SPECIAL | |
11518 && argvars[1].vval.v_number == VVAL_NULL) | |
11519 vim_unsetenv(name); | |
11520 else | |
11521 vim_setenv(name, tv_get_string_buf(&argvars[1], valbuf)); | |
11522 } | |
11523 | |
11524 /* | |
11428 * "setfperm({fname}, {mode})" function | 11525 * "setfperm({fname}, {mode})" function |
11429 */ | 11526 */ |
11430 static void | 11527 static void |
11431 f_setfperm(typval_T *argvars, typval_T *rettv) | 11528 f_setfperm(typval_T *argvars, typval_T *rettv) |
11432 { | 11529 { |