Mercurial > vim
comparison src/main.c @ 11032:516391d8865f v8.0.0405
patch 8.0.0405: v:progpath may become invalid after :cd
commit https://github.com/vim/vim/commit/08cab9608781c975b4acbad875862b842b29258d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Mar 4 14:37:18 2017 +0100
patch 8.0.0405: v:progpath may become invalid after :cd
Problem: v:progpath may become invalid after ":cd".
Solution: Turn v:progpath into a full path if needed.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 04 Mar 2017 14:45:05 +0100 |
parents | 835604f3c37a |
children | fde2cdef6b97 |
comparison
equal
deleted
inserted
replaced
11031:4dbc86032a4c | 11032:516391d8865f |
---|---|
54 static void exe_commands(mparm_T *parmp); | 54 static void exe_commands(mparm_T *parmp); |
55 static void source_startup_scripts(mparm_T *parmp); | 55 static void source_startup_scripts(mparm_T *parmp); |
56 static void main_start_gui(void); | 56 static void main_start_gui(void); |
57 # if defined(HAS_SWAP_EXISTS_ACTION) | 57 # if defined(HAS_SWAP_EXISTS_ACTION) |
58 static void check_swap_exists_action(void); | 58 static void check_swap_exists_action(void); |
59 # endif | |
60 # ifdef FEAT_EVAL | |
61 static void set_progpath(char_u *argv0); | |
59 # endif | 62 # endif |
60 # if defined(FEAT_CLIENTSERVER) || defined(PROTO) | 63 # if defined(FEAT_CLIENTSERVER) || defined(PROTO) |
61 static void exec_on_server(mparm_T *parmp); | 64 static void exec_on_server(mparm_T *parmp); |
62 static void prepare_server(mparm_T *parmp); | 65 static void prepare_server(mparm_T *parmp); |
63 static void cmdsrv_main(int *argc, char **argv, char_u *serverName_arg, char_u **serverStr); | 66 static void cmdsrv_main(int *argc, char **argv, char_u *serverName_arg, char_u **serverStr); |
1692 * /Vim.app/Contents/MacOS/Vim */ | 1695 * /Vim.app/Contents/MacOS/Vim */ |
1693 #endif | 1696 #endif |
1694 | 1697 |
1695 #ifdef FEAT_EVAL | 1698 #ifdef FEAT_EVAL |
1696 set_vim_var_string(VV_PROGNAME, initstr, -1); | 1699 set_vim_var_string(VV_PROGNAME, initstr, -1); |
1697 set_vim_var_string(VV_PROGPATH, (char_u *)parmp->argv[0], -1); | 1700 set_progpath((char_u *)parmp->argv[0]); |
1698 #endif | 1701 #endif |
1699 | 1702 |
1700 if (TOLOWER_ASC(initstr[0]) == 'r') | 1703 if (TOLOWER_ASC(initstr[0]) == 'r') |
1701 { | 1704 { |
1702 restricted = TRUE; | 1705 restricted = TRUE; |
3415 getout(1); | 3418 getout(1); |
3416 handle_swap_exists(NULL); | 3419 handle_swap_exists(NULL); |
3417 } | 3420 } |
3418 #endif | 3421 #endif |
3419 | 3422 |
3420 #endif | 3423 #endif /* NO_VIM_MAIN */ |
3421 | 3424 |
3422 #if defined(STARTUPTIME) || defined(PROTO) | 3425 #if defined(STARTUPTIME) || defined(PROTO) |
3423 static void time_diff(struct timeval *then, struct timeval *now); | 3426 static void time_diff(struct timeval *then, struct timeval *now); |
3424 | 3427 |
3425 static struct timeval prev_timeval; | 3428 static struct timeval prev_timeval; |
3522 fprintf(time_fd, ": %s\n", mesg); | 3525 fprintf(time_fd, ": %s\n", mesg); |
3523 } | 3526 } |
3524 } | 3527 } |
3525 | 3528 |
3526 #endif | 3529 #endif |
3530 | |
3531 #ifndef NO_VIM_MAIN | |
3532 static void | |
3533 set_progpath(char_u *argv0) | |
3534 { | |
3535 char_u *val = argv0; | |
3536 char_u buf[MAXPATHL]; | |
3537 | |
3538 /* A relative path containing a "/" will become invalid when using ":cd", | |
3539 * turn it into a full path. | |
3540 * On MS-Windows "vim.exe" is found in the current directory, thus also do | |
3541 * it when there is no path and the file exists. */ | |
3542 if ( !mch_isFullName(argv0) | |
3543 # ifdef WIN32 | |
3544 && mch_can_exe(argv0, NULL, TRUE) | |
3545 # else | |
3546 && gettail(argv0) != argv0 | |
3547 # endif | |
3548 && vim_FullName(argv0, buf, MAXPATHL, TRUE) != FAIL) | |
3549 val = buf; | |
3550 set_vim_var_string(VV_PROGPATH, val, -1); | |
3551 } | |
3552 | |
3553 #endif /* NO_VIM_MAIN */ | |
3527 | 3554 |
3528 #if (defined(FEAT_CLIENTSERVER) && !defined(NO_VIM_MAIN)) || defined(PROTO) | 3555 #if (defined(FEAT_CLIENTSERVER) && !defined(NO_VIM_MAIN)) || defined(PROTO) |
3529 | 3556 |
3530 /* | 3557 /* |
3531 * Common code for the X command server and the Win32 command server. | 3558 * Common code for the X command server and the Win32 command server. |