diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-04-21 22:30:08 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-04-21 22:30:08 +0200 |
commit | 2060892028e05b1325dc0759259254180669eb5e (patch) | |
tree | 26858ee1551ef811ca2f48eaea266253334fc2b5 /src/misc2.c | |
parent | 9980b37a80dc72eef05bf8862aaf475ab17790a5 (diff) | |
download | vim-git-2060892028e05b1325dc0759259254180669eb5e.tar.gz |
patch 8.0.1745: build failure on MS-Windowsv8.0.1745
Problem: Build failure on MS-Windows.
Solution: Build job arguments for MS-Windows. Fix allocating job twice.
Diffstat (limited to 'src/misc2.c')
-rw-r--r-- | src/misc2.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/misc2.c b/src/misc2.c index 9127e669a..cf957059c 100644 --- a/src/misc2.c +++ b/src/misc2.c @@ -6429,3 +6429,88 @@ elapsed(DWORD start_tick) } # endif #endif + +#if defined(FEAT_JOB_CHANNEL) \ + || (defined(UNIX) && (!defined(USE_SYSTEM) \ + || (defined(FEAT_GUI) && defined(FEAT_TERMINAL)))) \ + || defined(PROTO) +/* + * Parse "cmd" and put the white-separated parts in "argv". + * "argv" is an allocated array with "argc" entries and room for 4 more. + * Returns FAIL when out of memory. + */ + int +mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc) +{ + int i; + char_u *p, *d; + int inquote; + + /* + * Do this loop twice: + * 1: find number of arguments + * 2: separate them and build argv[] + */ + for (i = 0; i < 2; ++i) + { + p = skipwhite(cmd); + inquote = FALSE; + *argc = 0; + for (;;) + { + if (i == 1) + (*argv)[*argc] = (char *)p; + ++*argc; + d = p; + while (*p != NUL && (inquote || (*p != ' ' && *p != TAB))) + { + if (p[0] == '"') + /* quotes surrounding an argument and are dropped */ + inquote = !inquote; + else + { + if (p[0] == '\\' && p[1] != NUL) + { + /* First pass: skip over "\ " and "\"". + * Second pass: Remove the backslash. */ + ++p; + } + if (i == 1) + *d++ = *p; + } + ++p; + } + if (*p == NUL) + { + if (i == 1) + *d++ = NUL; + break; + } + if (i == 1) + *d++ = NUL; + p = skipwhite(p + 1); + } + if (*argv == NULL) + { + if (use_shcf) + { + /* Account for possible multiple args in p_shcf. */ + p = p_shcf; + for (;;) + { + p = skiptowhite(p); + if (*p == NUL) + break; + ++*argc; + p = skipwhite(p); + } + } + + *argv = (char **)alloc((unsigned)((*argc + 4) * sizeof(char *))); + if (*argv == NULL) /* out of memory */ + return FAIL; + } + } + return OK; +} +#endif |