mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 15:28:17 +00:00
Extract shell_skip_word
from mch_call_shell
This commit is contained in:
23
src/os/shell.c
Normal file
23
src/os/shell.c
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "os/shell.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include "ascii.h"
|
||||||
|
|
||||||
|
|
||||||
|
void shell_skip_word(char_u **ptr)
|
||||||
|
{
|
||||||
|
char_u *p = *ptr;
|
||||||
|
bool inquote = false;
|
||||||
|
|
||||||
|
// Move `p` to the end of shell word by advancing the pointer it while it's
|
||||||
|
// inside a quote or it's a non-whitespace character
|
||||||
|
while (*p && (inquote || (*p != ' ' && *p != TAB))) {
|
||||||
|
if (*p == '"')
|
||||||
|
// Found a quote character, switch the `inquote` flag
|
||||||
|
inquote = !inquote;
|
||||||
|
++p;
|
||||||
|
}
|
||||||
|
|
||||||
|
*ptr = p;
|
||||||
|
}
|
11
src/os/shell.h
Normal file
11
src/os/shell.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#ifndef NEOVIM_OS_SHELL_H
|
||||||
|
#define NEOVIM_OS_SHELL_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
void shell_skip_word(char_u **ptr);
|
||||||
|
|
||||||
|
#endif // NEOVIM_OS_SHELL_H
|
||||||
|
|
@@ -53,6 +53,7 @@
|
|||||||
#include "os/time.h"
|
#include "os/time.h"
|
||||||
#include "os/event.h"
|
#include "os/event.h"
|
||||||
#include "os/input.h"
|
#include "os/input.h"
|
||||||
|
#include "os/shell.h"
|
||||||
|
|
||||||
#include "os_unixx.h" /* unix includes for os_unix.c only */
|
#include "os_unixx.h" /* unix includes for os_unix.c only */
|
||||||
|
|
||||||
@@ -1705,7 +1706,6 @@ int options; /* SHELL_*, see vim.h */
|
|||||||
char_u *p_shcf_copy = NULL;
|
char_u *p_shcf_copy = NULL;
|
||||||
int i;
|
int i;
|
||||||
char_u *p;
|
char_u *p;
|
||||||
int inquote;
|
|
||||||
int pty_master_fd = -1; /* for pty's */
|
int pty_master_fd = -1; /* for pty's */
|
||||||
int fd_toshell[2]; /* for pipes */
|
int fd_toshell[2]; /* for pipes */
|
||||||
int fd_fromshell[2];
|
int fd_fromshell[2];
|
||||||
@@ -1723,18 +1723,10 @@ 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;
|
||||||
inquote = FALSE;
|
|
||||||
argc = 0;
|
argc = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
++argc;
|
++argc;
|
||||||
// Move `p` to the end of shell word by advancing the pointer it while it's
|
shell_skip_word(&p);
|
||||||
// inside a quote or it's a non-whitespace character
|
|
||||||
while (*p && (inquote || (*p != ' ' && *p != TAB))) {
|
|
||||||
if (*p == '"')
|
|
||||||
// Found a quote character, switch the `inquote` flag
|
|
||||||
inquote = !inquote;
|
|
||||||
++p;
|
|
||||||
}
|
|
||||||
if (*p == NUL)
|
if (*p == NUL)
|
||||||
break;
|
break;
|
||||||
// Move to the next word
|
// Move to the next word
|
||||||
@@ -1759,16 +1751,11 @@ int options; /* SHELL_*, see vim.h */
|
|||||||
|
|
||||||
// Build argv[]
|
// Build argv[]
|
||||||
p = newcmd;
|
p = newcmd;
|
||||||
inquote = FALSE;
|
|
||||||
argc = 0;
|
argc = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
argv[argc] = (char *)p;
|
argv[argc] = (char *)p;
|
||||||
++argc;
|
++argc;
|
||||||
while (*p && (inquote || (*p != ' ' && *p != TAB))) {
|
shell_skip_word(&p);
|
||||||
if (*p == '"')
|
|
||||||
inquote = !inquote;
|
|
||||||
++p;
|
|
||||||
}
|
|
||||||
if (*p == NUL)
|
if (*p == NUL)
|
||||||
break;
|
break;
|
||||||
// Terminate the word
|
// Terminate the word
|
||||||
|
Reference in New Issue
Block a user