diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-02-02 21:17:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-02 21:17:37 +0800 |
commit | e98decf9a68e41b09214aa60b77d0db29b7d648a (patch) | |
tree | 6a0a47d9f59209b1230637a55b10f25bb72c71d6 /src | |
parent | 1bf645918e94e7e8f770592484164f1ee303f24e (diff) | |
download | rneovim-e98decf9a68e41b09214aa60b77d0db29b7d648a.tar.gz rneovim-e98decf9a68e41b09214aa60b77d0db29b7d648a.tar.bz2 rneovim-e98decf9a68e41b09214aa60b77d0db29b7d648a.zip |
feat(quickfix): support -q - to read 'errorfile' from stdin (#27303)
Note that this only works when stdin is a pipe.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/main.c | 1 | ||||
-rw-r--r-- | src/nvim/os/fileio.c | 16 | ||||
-rw-r--r-- | src/nvim/os/fs.c | 17 | ||||
-rw-r--r-- | src/nvim/quickfix.c | 4 |
4 files changed, 22 insertions, 16 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c index 6d71dc618a..f858313682 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1016,6 +1016,7 @@ static bool edit_stdin(mparm_T *parmp) && !(embedded_mode && stdin_fd <= 0) && (!exmode_active || parmp->input_istext) && !stdin_isatty + && parmp->edit_type <= EDIT_STDIN && parmp->scriptin == NULL; // `-s -` was not given. return parmp->had_stdin_file || implicit; } diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c index 0141db7553..d24681a156 100644 --- a/src/nvim/os/fileio.c +++ b/src/nvim/os/fileio.c @@ -25,10 +25,6 @@ #include "nvim/rbuffer_defs.h" #include "nvim/types_defs.h" -#ifdef MSWIN -# include "nvim/os/os_win_console.h" -#endif - #ifdef HAVE_SYS_UIO_H # include <sys/uio.h> #endif @@ -179,17 +175,7 @@ FileDescriptor *file_open_stdin(void) FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT { int error; - int stdin_dup_fd; - if (stdin_fd > 0) { - stdin_dup_fd = stdin_fd; - } else { - stdin_dup_fd = os_dup(STDIN_FILENO); -#ifdef MSWIN - // Replace the original stdin with the console input handle. - os_replace_stdin_to_conin(); -#endif - } - FileDescriptor *const stdin_dup = file_open_fd_new(&error, stdin_dup_fd, + FileDescriptor *const stdin_dup = file_open_fd_new(&error, os_open_stdin_fd(), kFileReadOnly|kFileNonBlocking); assert(stdin_dup != NULL); if (error != 0) { diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index d80539708d..566d51f30a 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -55,6 +55,7 @@ #ifdef MSWIN # include "nvim/mbyte.h" # include "nvim/option.h" +# include "nvim/os/os_win_console.h" # include "nvim/strings.h" #endif @@ -541,6 +542,22 @@ os_dup_dup: return ret; } +/// Open the file descriptor for stdin. +int os_open_stdin_fd(void) +{ + int stdin_dup_fd; + if (stdin_fd > 0) { + stdin_dup_fd = stdin_fd; + } else { + stdin_dup_fd = os_dup(STDIN_FILENO); +#ifdef MSWIN + // Replace the original stdin with the console input handle. + os_replace_stdin_to_conin(); +#endif + } + return stdin_dup_fd; +} + /// Read from a file /// /// Handles EINTR and ENOMEM, but not other errors. diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 801c00933a..14758c8cea 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -1065,7 +1065,9 @@ static int qf_setup_state(qfstate_T *pstate, char *restrict enc, const char *res } if (efile != NULL - && (pstate->fd = os_fopen(efile, "r")) == NULL) { + && (pstate->fd = (strequal(efile, "-") + ? fdopen(os_open_stdin_fd(), "r") + : os_fopen(efile, "r"))) == NULL) { semsg(_(e_openerrf), efile); return FAIL; } |