mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 14:58:18 +00:00
Extract shell_count_argc
from mch_call_shell
This commit is contained in:
@@ -2,12 +2,14 @@
|
|||||||
|
|
||||||
#include "os/shell.h"
|
#include "os/shell.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include "vim.h"
|
||||||
#include "ascii.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;
|
bool inquote = false;
|
||||||
|
|
||||||
// Move `p` to the end of shell word by advancing the pointer it while it's
|
// 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;
|
++p;
|
||||||
}
|
}
|
||||||
|
|
||||||
*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;
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
void shell_skip_word(char_u **ptr);
|
void shell_skip_word(char_u **ptr);
|
||||||
|
int shell_count_argc(char_u **ptr);
|
||||||
|
|
||||||
#endif // NEOVIM_OS_SHELL_H
|
#endif // NEOVIM_OS_SHELL_H
|
||||||
|
|
||||||
|
@@ -1723,26 +1723,7 @@ int options; /* SHELL_*, see vim.h */
|
|||||||
|
|
||||||
// Count the number of arguments for the shell
|
// Count the number of arguments for the shell
|
||||||
p = newcmd;
|
p = newcmd;
|
||||||
argc = 0;
|
argc = shell_count_argc(&p);
|
||||||
while (true) {
|
|
||||||
++argc;
|
|
||||||
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;
|
|
||||||
++argc;
|
|
||||||
p = skipwhite(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate argv memory
|
// Allocate argv memory
|
||||||
argv = (char **)alloc((unsigned)((argc + 4) * sizeof(char *)));
|
argv = (char **)alloc((unsigned)((argc + 4) * sizeof(char *)));
|
||||||
|
Reference in New Issue
Block a user