Mercurial > vim
comparison src/misc1.c @ 7036:5f00b8d7148f v7.4.831
commit https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 25 13:57:04 2015 +0200
patch 7.4.831
Problem: When expanding on the command line and encountering an
error, the command is executed anyway.
Solution: Bail out when an error is detected.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 25 Aug 2015 17:20:26 +0200 |
parents | e859731ea1cd |
children | 76042a56ab85 |
comparison
equal
deleted
inserted
replaced
7035:1804d2f6eb1d | 7036:5f00b8d7148f |
---|---|
10873 int i; | 10873 int i; |
10874 garray_T ga; | 10874 garray_T ga; |
10875 char_u *p; | 10875 char_u *p; |
10876 static int recursive = FALSE; | 10876 static int recursive = FALSE; |
10877 int add_pat; | 10877 int add_pat; |
10878 int retval = OK; | |
10878 #if defined(FEAT_SEARCHPATH) | 10879 #if defined(FEAT_SEARCHPATH) |
10879 int did_expand_in_path = FALSE; | 10880 int did_expand_in_path = FALSE; |
10880 #endif | 10881 #endif |
10881 | 10882 |
10882 /* | 10883 /* |
10922 add_pat = -1; | 10923 add_pat = -1; |
10923 p = pat[i]; | 10924 p = pat[i]; |
10924 | 10925 |
10925 #ifdef VIM_BACKTICK | 10926 #ifdef VIM_BACKTICK |
10926 if (vim_backtick(p)) | 10927 if (vim_backtick(p)) |
10928 { | |
10927 add_pat = expand_backtick(&ga, p, flags); | 10929 add_pat = expand_backtick(&ga, p, flags); |
10930 if (add_pat == -1) | |
10931 retval = FAIL; | |
10932 } | |
10928 else | 10933 else |
10929 #endif | 10934 #endif |
10930 { | 10935 { |
10931 /* | 10936 /* |
10932 * First expand environment variables, "~/" and "~user/". | 10937 * First expand environment variables, "~/" and "~user/". |
11011 *num_file = ga.ga_len; | 11016 *num_file = ga.ga_len; |
11012 *file = (ga.ga_data != NULL) ? (char_u **)ga.ga_data : (char_u **)""; | 11017 *file = (ga.ga_data != NULL) ? (char_u **)ga.ga_data : (char_u **)""; |
11013 | 11018 |
11014 recursive = FALSE; | 11019 recursive = FALSE; |
11015 | 11020 |
11016 return (ga.ga_data != NULL) ? OK : FAIL; | 11021 return (ga.ga_data != NULL) ? retval : FAIL; |
11017 } | 11022 } |
11018 | 11023 |
11019 # ifdef VIM_BACKTICK | 11024 # ifdef VIM_BACKTICK |
11020 | 11025 |
11021 /* | 11026 /* |
11029 } | 11034 } |
11030 | 11035 |
11031 /* | 11036 /* |
11032 * Expand an item in `backticks` by executing it as a command. | 11037 * Expand an item in `backticks` by executing it as a command. |
11033 * Currently only works when pat[] starts and ends with a `. | 11038 * Currently only works when pat[] starts and ends with a `. |
11034 * Returns number of file names found. | 11039 * Returns number of file names found, -1 if an error is encountered. |
11035 */ | 11040 */ |
11036 static int | 11041 static int |
11037 expand_backtick(gap, pat, flags) | 11042 expand_backtick(gap, pat, flags) |
11038 garray_T *gap; | 11043 garray_T *gap; |
11039 char_u *pat; | 11044 char_u *pat; |
11046 int i; | 11051 int i; |
11047 | 11052 |
11048 /* Create the command: lop off the backticks. */ | 11053 /* Create the command: lop off the backticks. */ |
11049 cmd = vim_strnsave(pat + 1, (int)STRLEN(pat) - 2); | 11054 cmd = vim_strnsave(pat + 1, (int)STRLEN(pat) - 2); |
11050 if (cmd == NULL) | 11055 if (cmd == NULL) |
11051 return 0; | 11056 return -1; |
11052 | 11057 |
11053 #ifdef FEAT_EVAL | 11058 #ifdef FEAT_EVAL |
11054 if (*cmd == '=') /* `={expr}`: Expand expression */ | 11059 if (*cmd == '=') /* `={expr}`: Expand expression */ |
11055 buffer = eval_to_string(cmd + 1, &p, TRUE); | 11060 buffer = eval_to_string(cmd + 1, &p, TRUE); |
11056 else | 11061 else |
11057 #endif | 11062 #endif |
11058 buffer = get_cmd_output(cmd, NULL, | 11063 buffer = get_cmd_output(cmd, NULL, |
11059 (flags & EW_SILENT) ? SHELL_SILENT : 0, NULL); | 11064 (flags & EW_SILENT) ? SHELL_SILENT : 0, NULL); |
11060 vim_free(cmd); | 11065 vim_free(cmd); |
11061 if (buffer == NULL) | 11066 if (buffer == NULL) |
11062 return 0; | 11067 return -1; |
11063 | 11068 |
11064 cmd = buffer; | 11069 cmd = buffer; |
11065 while (*cmd != NUL) | 11070 while (*cmd != NUL) |
11066 { | 11071 { |
11067 cmd = skipwhite(cmd); /* skip over white space */ | 11072 cmd = skipwhite(cmd); /* skip over white space */ |