diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-03-29 12:41:18 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-03-31 08:07:46 -0300 |
commit | 8a61c27b1e301bb342758434f23bd7828790dcdf (patch) | |
tree | e1749fdfee920419eb3da1d6a4f60ec32aec5ef5 /src/os/shell.c | |
parent | 2d28251a6e2850998f475c76a886121554c9b7e9 (diff) | |
download | rneovim-8a61c27b1e301bb342758434f23bd7828790dcdf.tar.gz rneovim-8a61c27b1e301bb342758434f23bd7828790dcdf.tar.bz2 rneovim-8a61c27b1e301bb342758434f23bd7828790dcdf.zip |
Extract `shell_count_argc` from `mch_call_shell`
Diffstat (limited to 'src/os/shell.c')
-rw-r--r-- | src/os/shell.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/os/shell.c b/src/os/shell.c index b2248541b9..51e6d65b5b 100644 --- a/src/os/shell.c +++ b/src/os/shell.c @@ -2,12 +2,14 @@ #include "os/shell.h" #include "types.h" +#include "vim.h" #include "ascii.h" +#include "charset.h" -void shell_skip_word(char_u **ptr) +void shell_skip_word(char_u **cmd) { - char_u *p = *ptr; + char_u *p = *cmd; bool inquote = false; // Move `p` to the end of shell word by advancing the pointer it while it's @@ -19,5 +21,35 @@ void shell_skip_word(char_u **ptr) ++p; } + *cmd = p; +} + +int shell_count_argc(char_u **ptr) +{ + int rv = 0; + char_u *p = *ptr; + + while (true) { + rv++; + shell_skip_word(&p); + if (*p == NUL) + break; + // Move to the next word + p = skipwhite(p); + } + + // Account for multiple args in p_shcf('shellcmdflag' option) + p = p_shcf; + while (true) { + // Same as above, but doesn't need to take quotes into consideration + p = skiptowhite(p); + if (*p == NUL) + break; + rv++; + p = skipwhite(p); + } + *ptr = p; + + return rv; } |