aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/os')
-rw-r--r--src/nvim/os/dl.c2
-rw-r--r--src/nvim/os/env.c64
-rw-r--r--src/nvim/os/fileio.c101
-rw-r--r--src/nvim/os/fileio.h43
-rw-r--r--src/nvim/os/fileio_defs.h43
-rw-r--r--src/nvim/os/fs.c29
-rw-r--r--src/nvim/os/fs.h2
-rw-r--r--src/nvim/os/input.c28
-rw-r--r--src/nvim/os/input.h2
-rw-r--r--src/nvim/os/lang.c40
-rw-r--r--src/nvim/os/os.h22
-rw-r--r--src/nvim/os/os_defs.h28
-rw-r--r--src/nvim/os/os_win_console.c38
-rw-r--r--src/nvim/os/process.c12
-rw-r--r--src/nvim/os/pty_conpty_win.c1
-rw-r--r--src/nvim/os/pty_conpty_win.h2
-rw-r--r--src/nvim/os/pty_process_unix.c14
-rw-r--r--src/nvim/os/pty_process_unix.h15
-rw-r--r--src/nvim/os/pty_process_win.c49
-rw-r--r--src/nvim/os/pty_process_win.h14
-rw-r--r--src/nvim/os/shell.c32
-rw-r--r--src/nvim/os/signal.c4
-rw-r--r--src/nvim/os/stdpaths.c5
-rw-r--r--src/nvim/os/time.c6
-rw-r--r--src/nvim/os/time.h2
-rw-r--r--src/nvim/os/tty.c49
-rw-r--r--src/nvim/os/tty.h5
-rw-r--r--src/nvim/os/users.c8
28 files changed, 336 insertions, 324 deletions
diff --git a/src/nvim/os/dl.c b/src/nvim/os/dl.c
index 1a8d847f79..c6982e4fa8 100644
--- a/src/nvim/os/dl.c
+++ b/src/nvim/os/dl.c
@@ -5,7 +5,7 @@
#include <stdint.h>
#include <uv.h>
-#include "nvim/gettext.h"
+#include "nvim/gettext_defs.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/os/dl.h"
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index 8620c79069..5b1cb01976 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -13,9 +13,9 @@
#include "nvim/buffer_defs.h"
#include "nvim/charset.h"
#include "nvim/cmdexpand.h"
+#include "nvim/cmdexpand_defs.h"
#include "nvim/eval.h"
-#include "nvim/func_attr.h"
-#include "nvim/gettext.h"
+#include "nvim/gettext_defs.h"
#include "nvim/globals.h"
#include "nvim/log.h"
#include "nvim/macros_defs.h"
@@ -25,8 +25,10 @@
#include "nvim/option_vars.h"
#include "nvim/os/fs.h"
#include "nvim/os/os.h"
+#include "nvim/os/os_defs.h"
#include "nvim/path.h"
#include "nvim/strings.h"
+#include "nvim/types_defs.h"
#include "nvim/version.h"
#include "nvim/vim_defs.h"
@@ -46,6 +48,10 @@
# include <sys/utsname.h>
#endif
+#ifdef INCLUDE_GENERATED_DECLARATIONS
+# include "os/env.c.generated.h"
+#endif
+
// Because `uv_os_getenv` requires allocating, we must manage a map to maintain
// the behavior of `os_getenv`.
static PMap(cstr_t) envmap = MAP_INIT;
@@ -55,8 +61,7 @@ static PMap(cstr_t) envmap = MAP_INIT;
const char *os_getenv(const char *name)
FUNC_ATTR_NONNULL_ALL
{
- char *e;
- size_t size = 64;
+ char *e = NULL;
if (name[0] == '\0') {
return NULL;
}
@@ -72,23 +77,31 @@ const char *os_getenv(const char *name)
}
pmap_del2(&envmap, name);
}
- e = xmalloc(size);
- r = uv_os_getenv(name, e, &size);
+#define INIT_SIZE 64
+ size_t size = INIT_SIZE;
+ char buf[INIT_SIZE];
+ r = uv_os_getenv(name, buf, &size);
if (r == UV_ENOBUFS) {
- e = xrealloc(e, size);
+ e = xmalloc(size);
r = uv_os_getenv(name, e, &size);
- }
- if (r != 0 || size == 0 || e[0] == '\0') {
- xfree(e);
+ if (r != 0 || size == 0 || e[0] == '\0') {
+ XFREE_CLEAR(e);
+ goto end;
+ }
+ } else if (r != 0 || size == 0 || buf[0] == '\0') {
e = NULL;
goto end;
+ } else {
+ // NB: `size` param of uv_os_getenv() includes the NUL-terminator,
+ // except when it does not include the NUL-terminator.
+ e = xmemdupz(buf, size);
}
pmap_put(cstr_t)(&envmap, xstrdup(name), e);
end:
if (r != 0 && r != UV_ENOENT && r != UV_UNKNOWN) {
ELOG("uv_os_getenv(%s) failed: %d %s", name, r, uv_err_name(r));
}
- return (e == NULL || size == 0 || e[0] == '\0') ? NULL : e;
+ return e;
}
/// Returns true if environment variable `name` is defined (even if empty).
@@ -507,6 +520,17 @@ void free_homedir(void)
xfree(homedir);
}
+void free_envmap(void)
+{
+ cstr_t name;
+ ptr_t e;
+ map_foreach(&envmap, name, e, {
+ xfree((char *)name);
+ xfree(e);
+ });
+ map_destroy(cstr_t, &envmap);
+}
+
#endif
/// Call expand_env() and store the result in an allocated string.
@@ -562,6 +586,9 @@ void expand_env_esc(char *restrict srcp, char *restrict dst, int dstlen, bool es
bool copy_char;
bool mustfree; // var was allocated, need to free it later
bool at_start = true; // at start of a name
+#if defined(BACKSLASH_IN_FILENAME)
+ char *const save_dst = dst;
+#endif
int prefix_len = (prefix == NULL) ? 0 : (int)strlen(prefix);
@@ -572,7 +599,7 @@ void expand_env_esc(char *restrict srcp, char *restrict dst, int dstlen, bool es
if (src[0] == '`' && src[1] == '=') {
var = src;
src += 2;
- (void)skip_expr(&src, NULL);
+ skip_expr(&src, NULL);
if (*src == '`') {
src++;
}
@@ -604,7 +631,7 @@ void expand_env_esc(char *restrict srcp, char *restrict dst, int dstlen, bool es
while (c-- > 0 && *tail != NUL && *tail != '}') {
*var++ = *tail++;
}
- } else // NOLINT
+ } else
#endif
{
while (c-- > 0 && *tail != NUL && vim_isIDc((uint8_t)(*tail))) {
@@ -702,7 +729,7 @@ void expand_env_esc(char *restrict srcp, char *restrict dst, int dstlen, bool es
// with it, skip a character
if (after_pathsep(dst, dst + c)
#if defined(BACKSLASH_IN_FILENAME)
- && dst[-1] != ':'
+ && (dst == save_dst || dst[-1] != ':')
#endif
&& vim_ispathsep(*tail)) {
tail++;
@@ -904,10 +931,7 @@ char *vim_getenv(const char *name)
// Don't do this when default_vimruntime_dir is non-empty.
char *vim_path = NULL;
if (vimruntime
-#ifdef HAVE_PATHDEF
- && *default_vimruntime_dir == NUL
-#endif
- ) {
+ && *default_vimruntime_dir == NUL) {
kos_env_path = os_getenv("VIM");
if (kos_env_path != NULL) {
vim_path = vim_version_dir(kos_env_path);
@@ -966,7 +990,6 @@ char *vim_getenv(const char *name)
assert(vim_path != exe_name);
}
-#ifdef HAVE_PATHDEF
// When there is a pathdef.c file we can use default_vim_dir and
// default_vimruntime_dir
if (vim_path == NULL) {
@@ -980,7 +1003,6 @@ char *vim_getenv(const char *name)
}
}
}
-#endif
// Set the environment variable, so that the new value can be found fast
// next time, and others can also use it (e.g. Perl).
@@ -1051,7 +1073,7 @@ size_t home_replace(const buf_T *const buf, const char *src, char *const dst, si
size_t usedlen = 0;
size_t flen = strlen(homedir_env_mod);
char *fbuf = NULL;
- (void)modify_fname(":p", false, &usedlen, &homedir_env_mod, &fbuf, &flen);
+ modify_fname(":p", false, &usedlen, &homedir_env_mod, &fbuf, &flen);
flen = strlen(homedir_env_mod);
assert(homedir_env_mod != homedir_env);
if (vim_ispathsep(homedir_env_mod[flen - 1])) {
diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c
index 79d6ac08e7..da6fb13768 100644
--- a/src/nvim/os/fileio.c
+++ b/src/nvim/os/fileio.c
@@ -12,7 +12,7 @@
#include <uv.h>
#include "auto/config.h"
-#include "nvim/gettext.h"
+#include "nvim/gettext_defs.h"
#include "nvim/globals.h"
#include "nvim/log.h"
#include "nvim/macros_defs.h"
@@ -22,12 +22,9 @@
#include "nvim/os/fs.h"
#include "nvim/os/os_defs.h"
#include "nvim/rbuffer.h"
+#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
@@ -132,69 +129,15 @@ int file_open_fd(FileDescriptor *const ret_fp, const int fd, const int flags)
return 0;
}
-/// Like file_open(), but allocate and return ret_fp
-///
-/// @param[out] error Error code, or 0 on success. @see os_strerror()
-/// @param[in] fname File name to open.
-/// @param[in] flags Flags, @see FileOpenFlags.
-/// @param[in] mode Permissions for the newly created file (ignored if flags
-/// does not have kFileCreate\*).
-///
-/// @return [allocated] Opened file or NULL in case of error.
-FileDescriptor *file_open_new(int *const error, const char *const fname, const int flags,
- const int mode)
- FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
-{
- FileDescriptor *const fp = xmalloc(sizeof(*fp));
- if ((*error = file_open(fp, fname, flags, mode)) != 0) {
- xfree(fp);
- return NULL;
- }
- return fp;
-}
-
-/// Like file_open_fd(), but allocate and return ret_fp
-///
-/// @param[out] error Error code, or 0 on success. @see os_strerror()
-/// @param[in] fd File descriptor to wrap.
-/// @param[in] flags Flags, @see FileOpenFlags.
-/// @param[in] mode Permissions for the newly created file (ignored if flags
-/// does not have FILE_CREATE\*).
-///
-/// @return [allocated] Opened file or NULL in case of error.
-FileDescriptor *file_open_fd_new(int *const error, const int fd, const int flags)
- FUNC_ATTR_NONNULL_ALL FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT
-{
- FileDescriptor *const fp = xmalloc(sizeof(*fp));
- if ((*error = file_open_fd(fp, fd, flags)) != 0) {
- xfree(fp);
- return NULL;
- }
- return fp;
-}
-
/// Opens standard input as a FileDescriptor.
-FileDescriptor *file_open_stdin(void)
- FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT
+int file_open_stdin(FileDescriptor *fp)
+ 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,
- kFileReadOnly|kFileNonBlocking);
- assert(stdin_dup != NULL);
+ int error = file_open_fd(fp, os_open_stdin_fd(), kFileReadOnly|kFileNonBlocking);
if (error != 0) {
ELOG("failed to open stdin: %s", os_strerror(error));
}
- return stdin_dup;
+ return error;
}
/// Close file and free its buffer
@@ -215,20 +158,6 @@ int file_close(FileDescriptor *const fp, const bool do_fsync)
return flush_error;
}
-/// Close and free file obtained using file_open_new()
-///
-/// @param[in,out] fp File to close.
-/// @param[in] do_fsync If true, use fsync() to write changes to disk.
-///
-/// @return 0 or error code.
-int file_free(FileDescriptor *const fp, const bool do_fsync)
- FUNC_ATTR_NONNULL_ALL
-{
- const int ret = file_close(fp, do_fsync);
- xfree(fp);
- return ret;
-}
-
/// Flush file modifications to disk
///
/// @param[in,out] fp File to work with.
@@ -437,24 +366,6 @@ ptrdiff_t file_skip(FileDescriptor *const fp, const size_t size)
return (ptrdiff_t)read_bytes;
}
-/// Msgpack callback for writing to a file
-///
-/// @param data File to write to.
-/// @param[in] buf Data to write.
-/// @param[in] len Length of the data to write.
-///
-/// @return 0 in case of success, -1 in case of error.
-int msgpack_file_write(void *data, const char *buf, size_t len)
- FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
-{
- assert(len < PTRDIFF_MAX);
- const ptrdiff_t written_bytes = file_write((FileDescriptor *)data, buf, len);
- if (written_bytes < 0) {
- return msgpack_file_write_error((int)written_bytes);
- }
- return 0;
-}
-
/// Print error which occurs when failing to write msgpack data
///
/// @param[in] error Error code of the error to print.
diff --git a/src/nvim/os/fileio.h b/src/nvim/os/fileio.h
index 72e7984c8a..e8fd2209db 100644
--- a/src/nvim/os/fileio.h
+++ b/src/nvim/os/fileio.h
@@ -1,20 +1,8 @@
#pragma once
-#include <stdbool.h>
-#include <stddef.h>
+#include <stddef.h> // IWYU pragma: keep
-#include "nvim/func_attr.h"
-#include "nvim/rbuffer.h"
-
-/// Structure used to read from/write to file
-typedef struct {
- int fd; ///< File descriptor.
- int _error; ///< Error code for use with RBuffer callbacks or zero.
- RBuffer *rv; ///< Read or write buffer.
- bool wr; ///< True if file is in write mode.
- bool eof; ///< True if end of file was encountered.
- bool non_blocking; ///< True if EAGAIN should not restart syscalls.
-} FileDescriptor;
+#include "nvim/os/fileio_defs.h" // IWYU pragma: keep
/// file_open() flags
typedef enum {
@@ -37,33 +25,6 @@ typedef enum {
kFileMkDir = 256,
} FileOpenFlags;
-static inline bool file_eof(const FileDescriptor *fp)
- REAL_FATTR_PURE REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_NONNULL_ALL;
-
-/// Check whether end of file was encountered
-///
-/// @param[in] fp File to check.
-///
-/// @return true if it was, false if it was not or read operation was never
-/// performed.
-static inline bool file_eof(const FileDescriptor *const fp)
-{
- return fp->eof && rbuffer_size(fp->rv) == 0;
-}
-
-static inline int file_fd(const FileDescriptor *fp)
- REAL_FATTR_PURE REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_NONNULL_ALL;
-
-/// Return the file descriptor associated with the FileDescriptor structure
-///
-/// @param[in] fp File to check.
-///
-/// @return File descriptor.
-static inline int file_fd(const FileDescriptor *const fp)
-{
- return fp->fd;
-}
-
enum {
/// Read or write buffer size
///
diff --git a/src/nvim/os/fileio_defs.h b/src/nvim/os/fileio_defs.h
new file mode 100644
index 0000000000..3dc8c7b22a
--- /dev/null
+++ b/src/nvim/os/fileio_defs.h
@@ -0,0 +1,43 @@
+#pragma once
+
+#include <stdbool.h>
+
+#include "nvim/func_attr.h"
+#include "nvim/rbuffer_defs.h"
+
+/// Structure used to read from/write to file
+typedef struct {
+ int fd; ///< File descriptor.
+ int _error; ///< Error code for use with RBuffer callbacks or zero.
+ RBuffer *rv; ///< Read or write buffer.
+ bool wr; ///< True if file is in write mode.
+ bool eof; ///< True if end of file was encountered.
+ bool non_blocking; ///< True if EAGAIN should not restart syscalls.
+} FileDescriptor;
+
+static inline bool file_eof(const FileDescriptor *fp)
+ REAL_FATTR_ALWAYS_INLINE REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_NONNULL_ALL;
+
+/// Check whether end of file was encountered
+///
+/// @param[in] fp File to check.
+///
+/// @return true if it was, false if it was not or read operation was never
+/// performed.
+static inline bool file_eof(const FileDescriptor *const fp)
+{
+ return fp->eof && rbuffer_size(fp->rv) == 0;
+}
+
+static inline int file_fd(const FileDescriptor *fp)
+ REAL_FATTR_ALWAYS_INLINE REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_NONNULL_ALL;
+
+/// Return the file descriptor associated with the FileDescriptor structure
+///
+/// @param[in] fp File to check.
+///
+/// @return File descriptor.
+static inline int file_fd(const FileDescriptor *const fp)
+{
+ return fp->fd;
+}
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index 8f939c3b40..ade745df2c 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -17,8 +17,8 @@
#endif
#include "auto/config.h"
-#include "nvim/func_attr.h"
#include "nvim/os/fs.h"
+#include "nvim/os/os_defs.h"
#if defined(HAVE_ACL)
# ifdef HAVE_SYS_ACL_H
@@ -33,8 +33,9 @@
# include <sys/xattr.h>
#endif
+#include "nvim/api/private/helpers.h"
#include "nvim/ascii_defs.h"
-#include "nvim/gettext.h"
+#include "nvim/gettext_defs.h"
#include "nvim/globals.h"
#include "nvim/log.h"
#include "nvim/macros_defs.h"
@@ -44,6 +45,7 @@
#include "nvim/os/os.h"
#include "nvim/path.h"
#include "nvim/types_defs.h"
+#include "nvim/ui.h"
#include "nvim/vim_defs.h"
#ifdef HAVE_SYS_UIO_H
@@ -53,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
@@ -90,7 +93,11 @@ int os_chdir(const char *path)
smsg(0, "chdir(%s)", path);
verbose_leave();
}
- return uv_chdir(path);
+ int err = uv_chdir(path);
+ if (err == 0) {
+ ui_call_chdir(cstr_as_string(path));
+ }
+ return err;
}
/// Get the name of current directory.
@@ -535,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/os/fs.h b/src/nvim/os/fs.h
index 56dd657f70..19cdb09c99 100644
--- a/src/nvim/os/fs.h
+++ b/src/nvim/os/fs.h
@@ -5,7 +5,7 @@
#include <stdio.h> // IWYU pragma: keep
#include <uv.h> // IWYU pragma: keep
-#include "nvim/os/fs_defs.h" // IWYU pragma: export
+#include "nvim/os/fs_defs.h" // IWYU pragma: keep
#include "nvim/types_defs.h" // IWYU pragma: keep
#ifdef INCLUDE_GENERATED_DECLARATIONS
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c
index f3bd1c7ed9..fab360c9af 100644
--- a/src/nvim/os/input.c
+++ b/src/nvim/os/input.c
@@ -8,13 +8,14 @@
#include "nvim/api/private/defs.h"
#include "nvim/ascii_defs.h"
#include "nvim/autocmd.h"
+#include "nvim/autocmd_defs.h"
+#include "nvim/buffer_defs.h"
#include "nvim/event/loop.h"
#include "nvim/event/multiqueue.h"
#include "nvim/event/rstream.h"
#include "nvim/event/stream.h"
-#include "nvim/func_attr.h"
#include "nvim/getchar.h"
-#include "nvim/gettext.h"
+#include "nvim/gettext_defs.h"
#include "nvim/globals.h"
#include "nvim/keycodes.h"
#include "nvim/log.h"
@@ -27,7 +28,9 @@
#include "nvim/os/time.h"
#include "nvim/profile.h"
#include "nvim/rbuffer.h"
+#include "nvim/rbuffer_defs.h"
#include "nvim/state.h"
+#include "nvim/state_defs.h"
#define READ_BUFFER_SIZE 0xfff
#define INPUT_BUFFER_SIZE (READ_BUFFER_SIZE * 4)
@@ -75,6 +78,13 @@ void input_stop(void)
stream_close(&read_stream, NULL, NULL);
}
+#ifdef EXITFREE
+void input_free_all_mem(void)
+{
+ rbuffer_free(input_buffer);
+}
+#endif
+
static void cursorhold_event(void **argv)
{
event_T event = State & MODE_INSERT ? EVENT_CURSORHOLDI : EVENT_CURSORHOLD;
@@ -85,11 +95,11 @@ static void cursorhold_event(void **argv)
static void create_cursorhold_event(bool events_enabled)
{
// If events are enabled and the queue has any items, this function should not
- // have been called(inbuf_poll would return kInputAvail)
+ // have been called (inbuf_poll would return kInputAvail).
// TODO(tarruda): Cursorhold should be implemented as a timer set during the
// `state_check` callback for the states where it can be triggered.
assert(!events_enabled || multiqueue_empty(main_loop.events));
- multiqueue_put(main_loop.events, cursorhold_event, 0);
+ multiqueue_put(main_loop.events, cursorhold_event, NULL);
}
static void restart_cursorhold_wait(int tb_change_cnt)
@@ -100,7 +110,7 @@ static void restart_cursorhold_wait(int tb_change_cnt)
/// Low level input function
///
-/// wait until either the input buffer is non-empty or, if `events` is not NULL
+/// Wait until either the input buffer is non-empty or, if `events` is not NULL
/// until `events` is non-empty.
int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt, MultiQueue *events)
{
@@ -304,7 +314,8 @@ static uint8_t check_multiclick(int code, int grid, int row, int col)
}
// For click events the number of clicks is updated.
- if (code == KE_LEFTMOUSE || code == KE_RIGHTMOUSE || code == KE_MIDDLEMOUSE) {
+ if (code == KE_LEFTMOUSE || code == KE_RIGHTMOUSE || code == KE_MIDDLEMOUSE
+ || code == KE_X1MOUSE || code == KE_X2MOUSE) {
uint64_t mouse_time = os_hrtime(); // time of current mouse click (ns)
// compute the time elapsed since the previous mouse click and
// convert p_mouse from ms to ns
@@ -408,7 +419,8 @@ static unsigned handle_mouse_event(const char **ptr, uint8_t *buf, unsigned bufs
size_t input_enqueue_mouse(int code, uint8_t modifier, int grid, int row, int col)
{
modifier |= check_multiclick(code, grid, row, col);
- uint8_t buf[7], *p = buf;
+ uint8_t buf[7];
+ uint8_t *p = buf;
if (modifier) {
p[0] = K_SPECIAL;
p[1] = KS_MODIFIER;
@@ -531,7 +543,7 @@ bool os_input_ready(MultiQueue *events)
{
return (typebuf_was_filled // API call filled typeahead
|| rbuffer_size(input_buffer) // Input buffer filled
- || pending_events(events)); // Events must be processed
+ || pending_events(events)); // Events must be processed
}
// Exit because of an input read error.
diff --git a/src/nvim/os/input.h b/src/nvim/os/input.h
index 4b104b0b50..abef46072b 100644
--- a/src/nvim/os/input.h
+++ b/src/nvim/os/input.h
@@ -4,7 +4,7 @@
#include <stdint.h> // IWYU pragma: keep
#include "nvim/api/private/defs.h" // IWYU pragma: keep
-#include "nvim/event/multiqueue.h"
+#include "nvim/event/defs.h" // IWYU pragma: keep
#include "nvim/macros_defs.h"
EXTERN bool used_stdin INIT( = false);
diff --git a/src/nvim/os/lang.c b/src/nvim/os/lang.c
index 17d179a56a..fb534ab2f4 100644
--- a/src/nvim/os/lang.c
+++ b/src/nvim/os/lang.c
@@ -19,7 +19,8 @@
#include "nvim/eval.h"
#include "nvim/ex_cmds_defs.h"
#include "nvim/garray.h"
-#include "nvim/gettext.h"
+#include "nvim/gettext_defs.h"
+#include "nvim/globals.h"
#include "nvim/macros_defs.h"
#include "nvim/memory.h"
#include "nvim/message.h"
@@ -79,17 +80,21 @@ static char *get_mess_env(void)
return get_locale_val(LC_MESSAGES);
#else
char *p = (char *)os_getenv("LC_ALL");
+ if (p != NULL) {
+ return p;
+ }
+
+ p = (char *)os_getenv("LC_MESSAGES");
+ if (p != NULL) {
+ return p;
+ }
+
+ p = (char *)os_getenv("LANG");
+ if (p != NULL && ascii_isdigit(*p)) {
+ p = NULL; // ignore something like "1043"
+ }
if (p == NULL) {
- p = (char *)os_getenv("LC_MESSAGES");
- if (p == NULL) {
- p = (char *)os_getenv("LANG");
- if (p != NULL && ascii_isdigit(*p)) {
- p = NULL; // ignore something like "1043"
- }
- if (p == NULL) {
- p = get_locale_val(LC_CTYPE);
- }
- }
+ p = get_locale_val(LC_CTYPE);
}
return p;
#endif
@@ -99,9 +104,7 @@ static char *get_mess_env(void)
/// Also do "v:lc_time"and "v:ctype".
void set_lang_var(void)
{
- const char *loc;
-
- loc = get_locale_val(LC_CTYPE);
+ const char *loc = get_locale_val(LC_CTYPE);
set_vim_var_string(VV_CTYPE, loc, -1);
loc = get_mess_env();
@@ -142,8 +145,6 @@ void init_locale(void)
void ex_language(exarg_T *eap)
{
char *loc;
- char *p;
- char *name;
int what = LC_ALL;
char *whatstr = "";
#ifdef LC_MESSAGES
@@ -152,12 +153,12 @@ void ex_language(exarg_T *eap)
# define VIM_LC_MESSAGES 6789
#endif
- name = eap->arg;
+ char *name = eap->arg;
// Check for "messages {name}", "ctype {name}" or "time {name}" argument.
// Allow abbreviation, but require at least 3 characters to avoid
// confusion with a two letter language name "me" or "ct".
- p = skiptowhite(eap->arg);
+ char *p = skiptowhite(eap->arg);
if ((*p == NUL || ascii_iswhite(*p)) && p - eap->arg >= 3) {
if (STRNICMP(eap->arg, "messages", p - eap->arg) == 0) {
what = VIM_LC_MESSAGES;
@@ -248,7 +249,6 @@ static bool did_init_locales = false;
static char **find_locales(void)
{
garray_T locales_ga;
- char *loc;
char *saveptr = NULL;
// Find all available locales by running command "locale -a". If this
@@ -261,7 +261,7 @@ static char **find_locales(void)
// Transform locale_a string where each locale is separated by "\n"
// into an array of locale strings.
- loc = os_strtok(locale_a, "\n", &saveptr);
+ char *loc = os_strtok(locale_a, "\n", &saveptr);
while (loc != NULL) {
loc = xstrdup(loc);
diff --git a/src/nvim/os/os.h b/src/nvim/os/os.h
index 302d84d066..1a942d062b 100644
--- a/src/nvim/os/os.h
+++ b/src/nvim/os/os.h
@@ -1,24 +1,18 @@
#pragma once
-#include <stddef.h> // IWYU pragma: keep
-#include <stdint.h> // IWYU pragma: keep
-#include <uv.h> // IWYU pragma: keep
+#include <stddef.h>
+#include <stdint.h>
+#include <uv.h>
-#include "nvim/buffer_defs.h" // IWYU pragma: keep
-#include "nvim/cmdexpand_defs.h" // IWYU pragma: keep
-#include "nvim/garray_defs.h" // IWYU pragma: keep
-#include "nvim/os/os_defs.h" // IWYU pragma: export
-#include "nvim/os/stdpaths_defs.h" // IWYU pragma: keep
+#include "nvim/cmdexpand_defs.h"
+#include "nvim/garray_defs.h"
+#include "nvim/os/os_defs.h"
+#include "nvim/os/stdpaths_defs.h"
+#include "nvim/types_defs.h"
-#define HAVE_PATHDEF
-
-// Some file names are stored in pathdef.c, which is generated from the
-// Makefile to make their value depend on the Makefile.
-#ifdef HAVE_PATHDEF
extern char *default_vim_dir;
extern char *default_vimruntime_dir;
extern char *default_lib_dir;
-#endif
#ifdef INCLUDE_GENERATED_DECLARATIONS
// IWYU pragma: begin_exports
diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h
index 12de55a227..db575e005a 100644
--- a/src/nvim/os/os_defs.h
+++ b/src/nvim/os/os_defs.h
@@ -113,3 +113,31 @@
&& (defined(S_ISCHR) || defined(S_IFCHR))
# define OPEN_CHR_FILES
#endif
+
+// We use 64-bit file functions here, if available. E.g. ftello() returns
+// off_t instead of long, which helps if long is 32 bit and off_t is 64 bit.
+// We assume that when fseeko() is available then ftello() is too.
+// Note that Windows has different function names.
+#if (defined(_MSC_VER) && (_MSC_VER >= 1300)) || defined(__MINGW32__)
+typedef __int64 off_T;
+# ifdef __MINGW32__
+# define vim_lseek lseek64
+# define vim_fseek fseeko64
+# define vim_ftell ftello64
+# else
+# define vim_lseek _lseeki64
+# define vim_fseek _fseeki64
+# define vim_ftell _ftelli64
+# endif
+#else
+typedef off_t off_T;
+# ifdef HAVE_FSEEKO
+# define vim_lseek lseek
+# define vim_ftell ftello
+# define vim_fseek fseeko
+# else
+# define vim_lseek lseek
+# define vim_ftell ftell
+# define vim_fseek(a, b, c) fseek(a, (long)b, c)
+# endif
+#endif
diff --git a/src/nvim/os/os_win_console.c b/src/nvim/os/os_win_console.c
index 816e81e997..953d291290 100644
--- a/src/nvim/os/os_win_console.c
+++ b/src/nvim/os/os_win_console.c
@@ -1,6 +1,7 @@
#include <string.h>
#include "nvim/globals.h"
+#include "nvim/memory.h"
#include "nvim/os/fs.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
@@ -105,3 +106,40 @@ void os_title_reset(void)
{
SetConsoleTitle(origTitle);
}
+
+#if !defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING)
+# define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
+#endif
+/// Guesses the terminal-type. Calls SetConsoleMode() and uv_set_vterm_state()
+/// if appropriate.
+///
+/// @param[in,out] term Name of the guessed terminal, statically-allocated
+/// @param out_fd stdout file descriptor
+void os_tty_guess_term(const char **term, int out_fd)
+{
+ bool conemu_ansi = strequal(os_getenv("ConEmuANSI"), "ON");
+ bool vtp = false;
+
+ HANDLE handle = (HANDLE)_get_osfhandle(out_fd);
+ DWORD dwMode;
+ if (handle != INVALID_HANDLE_VALUE && GetConsoleMode(handle, &dwMode)) {
+ dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
+ if (SetConsoleMode(handle, dwMode)) {
+ vtp = true;
+ }
+ }
+
+ if (*term == NULL) {
+ if (vtp) {
+ *term = "vtpcon";
+ } else if (conemu_ansi) {
+ *term = "conemu";
+ } else {
+ *term = "win32con";
+ }
+ }
+
+ if (conemu_ansi) {
+ uv_tty_set_vterm_state(UV_TTY_SUPPORTED);
+ }
+}
diff --git a/src/nvim/os/process.c b/src/nvim/os/process.c
index d9ec3a7a8a..e8d38d5b8a 100644
--- a/src/nvim/os/process.c
+++ b/src/nvim/os/process.c
@@ -44,7 +44,7 @@
#endif
#ifdef INCLUDE_GENERATED_DECLARATIONS
-# include "os/process.c.generated.h" // IWYU pragma: export
+# include "os/process.c.generated.h"
#endif
#ifdef MSWIN
@@ -114,6 +114,7 @@ bool os_proc_tree_kill(int pid, int sig)
/// @param[out] proc_count Number of child processes.
/// @return 0 on success, 1 if process not found, 2 on other error.
int os_proc_children(int ppid, int **proc_list, size_t *proc_count)
+ FUNC_ATTR_NONNULL_ALL
{
if (ppid < 0) {
return 2;
@@ -229,7 +230,7 @@ int os_proc_children(int ppid, int **proc_list, size_t *proc_count)
///
/// @param pid Process to inspect.
/// @return Map of process properties, empty on error.
-Dictionary os_proc_info(int pid)
+Dictionary os_proc_info(int pid, Arena *arena)
{
Dictionary pinfo = ARRAY_DICT_INIT;
PROCESSENTRY32 pe;
@@ -257,9 +258,10 @@ Dictionary os_proc_info(int pid)
CloseHandle(h);
if (pe.th32ProcessID == (DWORD)pid) {
- PUT(pinfo, "pid", INTEGER_OBJ(pid));
- PUT(pinfo, "ppid", INTEGER_OBJ((int)pe.th32ParentProcessID));
- PUT(pinfo, "name", CSTR_TO_OBJ(pe.szExeFile));
+ pinfo = arena_dict(arena, 3);
+ PUT_C(pinfo, "pid", INTEGER_OBJ(pid));
+ PUT_C(pinfo, "ppid", INTEGER_OBJ((int)pe.th32ParentProcessID));
+ PUT_C(pinfo, "name", CSTR_TO_ARENA_OBJ(arena, pe.szExeFile));
}
return pinfo;
diff --git a/src/nvim/os/pty_conpty_win.c b/src/nvim/os/pty_conpty_win.c
index 53169c0ef8..e7697880af 100644
--- a/src/nvim/os/pty_conpty_win.c
+++ b/src/nvim/os/pty_conpty_win.c
@@ -1,5 +1,6 @@
#include <uv.h>
+#include "nvim/log.h"
#include "nvim/os/os.h"
#include "nvim/os/pty_conpty_win.h"
#include "nvim/vim_defs.h"
diff --git a/src/nvim/os/pty_conpty_win.h b/src/nvim/os/pty_conpty_win.h
index aa04cd1e84..a0c6a06cda 100644
--- a/src/nvim/os/pty_conpty_win.h
+++ b/src/nvim/os/pty_conpty_win.h
@@ -7,7 +7,7 @@
# define HPCON VOID *
#endif
-extern HRESULT(WINAPI *pCreatePseudoConsole) // NOLINT(whitespace/parens)
+extern HRESULT(WINAPI *pCreatePseudoConsole)
(COORD, HANDLE, HANDLE, DWORD, HPCON *);
extern HRESULT(WINAPI *pResizePseudoConsole)(HPCON, COORD);
extern void(WINAPI *pClosePseudoConsole)(HPCON);
diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c
index f801646967..4d34e8fac4 100644
--- a/src/nvim/os/pty_process_unix.c
+++ b/src/nvim/os/pty_process_unix.c
@@ -32,15 +32,15 @@
#include "auto/config.h"
#include "klib/klist.h"
#include "nvim/eval/typval.h"
+#include "nvim/event/defs.h"
#include "nvim/event/loop.h"
#include "nvim/event/process.h"
-#include "nvim/event/stream.h"
-#include "nvim/func_attr.h"
#include "nvim/log.h"
#include "nvim/os/fs.h"
#include "nvim/os/os_defs.h"
#include "nvim/os/pty_process.h"
#include "nvim/os/pty_process_unix.h"
+#include "nvim/types_defs.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/pty_process_unix.c.generated.h"
@@ -405,3 +405,13 @@ static void chld_handler(uv_signal_t *handle, int signum)
proc->internal_exit_cb(proc);
}
}
+
+PtyProcess pty_process_init(Loop *loop, void *data)
+{
+ PtyProcess rv;
+ rv.process = process_init(loop, kProcessTypePty, data);
+ rv.width = 80;
+ rv.height = 24;
+ rv.tty_fd = -1;
+ return rv;
+}
diff --git a/src/nvim/os/pty_process_unix.h b/src/nvim/os/pty_process_unix.h
index 92cc582832..1a77ae5fd5 100644
--- a/src/nvim/os/pty_process_unix.h
+++ b/src/nvim/os/pty_process_unix.h
@@ -4,26 +4,15 @@
#include <stdint.h>
#include <sys/ioctl.h>
-#include "nvim/event/loop.h"
-#include "nvim/event/process.h"
+#include "nvim/event/defs.h"
-typedef struct pty_process {
+typedef struct {
Process process;
uint16_t width, height;
struct winsize winsize;
int tty_fd;
} PtyProcess;
-static inline PtyProcess pty_process_init(Loop *loop, void *data)
-{
- PtyProcess rv;
- rv.process = process_init(loop, kProcessTypePty, data);
- rv.width = 80;
- rv.height = 24;
- rv.tty_fd = -1;
- return rv;
-}
-
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/pty_process_unix.h.generated.h"
#endif
diff --git a/src/nvim/os/pty_process_win.c b/src/nvim/os/pty_process_win.c
index ca2dce36ea..12831ff05f 100644
--- a/src/nvim/os/pty_process_win.c
+++ b/src/nvim/os/pty_process_win.c
@@ -4,6 +4,8 @@
#include "nvim/ascii_defs.h"
#include "nvim/eval/typval.h"
+#include "nvim/event/loop.h"
+#include "nvim/log.h"
#include "nvim/mbyte.h"
#include "nvim/memory.h"
#include "nvim/os/os.h"
@@ -21,9 +23,19 @@ static void CALLBACK pty_process_finish1(void *context, BOOLEAN unused)
Process *proc = (Process *)ptyproc;
os_conpty_free(ptyproc->conpty);
- uv_timer_init(&proc->loop->uv, &ptyproc->wait_eof_timer);
- ptyproc->wait_eof_timer.data = (void *)ptyproc;
- uv_timer_start(&ptyproc->wait_eof_timer, wait_eof_timer_cb, 200, 200);
+ // NB: pty_process_finish1() is called on a separate thread,
+ // but the timer only works properly if it's started by the main thread.
+ loop_schedule_fast(proc->loop, event_create(start_wait_eof_timer, ptyproc));
+}
+
+static void start_wait_eof_timer(void **argv)
+ FUNC_ATTR_NONNULL_ALL
+{
+ PtyProcess *ptyproc = (PtyProcess *)argv[0];
+
+ if (ptyproc->finish_wait != NULL) {
+ uv_timer_start(&ptyproc->wait_eof_timer, wait_eof_timer_cb, 200, 200);
+ }
}
/// @returns zero on success, or negative error code.
@@ -104,6 +116,8 @@ int pty_process_spawn(PtyProcess *ptyproc)
}
proc->pid = (int)GetProcessId(process_handle);
+ uv_timer_init(&proc->loop->uv, &ptyproc->wait_eof_timer);
+ ptyproc->wait_eof_timer.data = (void *)ptyproc;
if (!RegisterWaitForSingleObject(&ptyproc->finish_wait,
process_handle,
pty_process_finish1,
@@ -163,6 +177,16 @@ void pty_process_close(PtyProcess *ptyproc)
pty_process_close_master(ptyproc);
+ if (ptyproc->finish_wait != NULL) {
+ UnregisterWaitEx(ptyproc->finish_wait, NULL);
+ ptyproc->finish_wait = NULL;
+ uv_close((uv_handle_t *)&ptyproc->wait_eof_timer, NULL);
+ }
+ if (ptyproc->process_handle != NULL) {
+ CloseHandle(ptyproc->process_handle);
+ ptyproc->process_handle = NULL;
+ }
+
if (proc->internal_close_cb) {
proc->internal_close_cb(proc);
}
@@ -191,6 +215,7 @@ static void wait_eof_timer_cb(uv_timer_t *wait_eof_timer)
PtyProcess *ptyproc = wait_eof_timer->data;
Process *proc = (Process *)ptyproc;
+ assert(ptyproc->finish_wait != NULL);
if (proc->out.closed || proc->out.did_eof || !uv_is_readable(proc->out.uvstream)) {
uv_timer_stop(&ptyproc->wait_eof_timer);
pty_process_finish2(ptyproc);
@@ -202,16 +227,10 @@ static void pty_process_finish2(PtyProcess *ptyproc)
{
Process *proc = (Process *)ptyproc;
- UnregisterWaitEx(ptyproc->finish_wait, NULL);
- uv_close((uv_handle_t *)&ptyproc->wait_eof_timer, NULL);
-
DWORD exit_code = 0;
GetExitCodeProcess(ptyproc->process_handle, &exit_code);
proc->status = proc->exit_signal ? 128 + proc->exit_signal : (int)exit_code;
- CloseHandle(ptyproc->process_handle);
- ptyproc->process_handle = NULL;
-
proc->internal_exit_cb(proc);
}
@@ -407,3 +426,15 @@ cleanup:
return rc;
}
+
+PtyProcess pty_process_init(Loop *loop, void *data)
+{
+ PtyProcess rv;
+ rv.process = process_init(loop, kProcessTypePty, data);
+ rv.width = 80;
+ rv.height = 24;
+ rv.conpty = NULL;
+ rv.finish_wait = NULL;
+ rv.process_handle = NULL;
+ return rv;
+}
diff --git a/src/nvim/os/pty_process_win.h b/src/nvim/os/pty_process_win.h
index 26cf387e54..3528f6bfe5 100644
--- a/src/nvim/os/pty_process_win.h
+++ b/src/nvim/os/pty_process_win.h
@@ -4,7 +4,7 @@
#include <uv.h>
#include "nvim/event/process.h"
-#include "nvim/lib/queue.h"
+#include "nvim/lib/queue_defs.h"
#include "nvim/os/pty_conpty_win.h"
typedef struct pty_process {
@@ -22,18 +22,6 @@ typedef struct arg_node {
QUEUE node; // QUEUE structure.
} ArgNode;
-static inline PtyProcess pty_process_init(Loop *loop, void *data)
-{
- PtyProcess rv;
- rv.process = process_init(loop, kProcessTypePty, data);
- rv.width = 80;
- rv.height = 24;
- rv.conpty = NULL;
- rv.finish_wait = NULL;
- rv.process_handle = NULL;
- return rv;
-}
-
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/pty_process_win.h.generated.h"
#endif
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c
index 191be784e8..46ba13c4cd 100644
--- a/src/nvim/os/shell.c
+++ b/src/nvim/os/shell.c
@@ -8,9 +8,11 @@
#include "auto/config.h"
#include "klib/kvec.h"
#include "nvim/ascii_defs.h"
+#include "nvim/buffer_defs.h"
#include "nvim/charset.h"
#include "nvim/eval.h"
#include "nvim/eval/typval_defs.h"
+#include "nvim/event/defs.h"
#include "nvim/event/libuv_process.h"
#include "nvim/event/loop.h"
#include "nvim/event/multiqueue.h"
@@ -20,8 +22,7 @@
#include "nvim/event/wstream.h"
#include "nvim/ex_cmds.h"
#include "nvim/fileio.h"
-#include "nvim/func_attr.h"
-#include "nvim/gettext.h"
+#include "nvim/gettext_defs.h"
#include "nvim/globals.h"
#include "nvim/macros_defs.h"
#include "nvim/main.h"
@@ -31,6 +32,7 @@
#include "nvim/message.h"
#include "nvim/option_vars.h"
#include "nvim/os/fs.h"
+#include "nvim/os/os_defs.h"
#include "nvim/os/shell.h"
#include "nvim/os/signal.h"
#include "nvim/os/time.h"
@@ -38,6 +40,7 @@
#include "nvim/pos_defs.h"
#include "nvim/profile.h"
#include "nvim/rbuffer.h"
+#include "nvim/rbuffer_defs.h"
#include "nvim/state_defs.h"
#include "nvim/strings.h"
#include "nvim/tag.h"
@@ -118,14 +121,10 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in
int i;
size_t len;
char *p;
- bool dir;
char *extra_shell_arg = NULL;
ShellOpts shellopts = kShellOptExpand | kShellOptSilent;
int j;
char *tempname;
- char *command;
- FILE *fd;
- char *buffer;
#define STYLE_ECHO 0 // use "echo", the default
#define STYLE_GLOB 1 // use "glob", for csh
#define STYLE_VIMGLOB 2 // use "vimglob", for Posix sh
@@ -241,7 +240,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in
len += sizeof("egin;" " end") - 1;
}
- command = xmalloc(len);
+ char *command = xmalloc(len);
// Build the shell command:
// - Set $nonomatch depending on EW_NOTFOUND (hopefully the shell
@@ -389,7 +388,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in
}
// read the names from the file into memory
- fd = fopen(tempname, READBIN);
+ FILE *fd = fopen(tempname, READBIN);
if (fd == NULL) {
// Something went wrong, perhaps a file name with a special char.
if (!(flags & EW_SILENT)) {
@@ -416,7 +415,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in
#endif
len = (size_t)templen;
fseek(fd, 0, SEEK_SET);
- buffer = xmalloc(len + 1);
+ char *buffer = xmalloc(len + 1);
// fread() doesn't terminate buffer with NUL;
// appropriate termination (not always NUL) is done below.
size_t readlen = fread(buffer, 1, len, fd);
@@ -537,7 +536,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in
}
// check if this entry should be included
- dir = (os_isdir((*file)[i]));
+ bool dir = (os_isdir((*file)[i]));
if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) {
continue;
}
@@ -670,7 +669,8 @@ char *shell_argv_to_str(char **const argv)
int os_call_shell(char *cmd, ShellOpts opts, char *extra_args)
{
DynamicBuffer input = DYNAMIC_BUFFER_INIT;
- char *output = NULL, **output_ptr = NULL;
+ char *output = NULL;
+ char **output_ptr = NULL;
int current_state = State;
bool forward_output = true;
@@ -702,7 +702,7 @@ int os_call_shell(char *cmd, ShellOpts opts, char *extra_args)
xfree(input.data);
if (output) {
- (void)write_output(output, nread, true);
+ write_output(output, nread, true);
xfree(output);
}
@@ -1122,7 +1122,8 @@ static void out_data_ring(char *output, size_t size)
static void out_data_append_to_screen(char *output, size_t *count, bool eof)
FUNC_ATTR_NONNULL_ALL
{
- char *p = output, *end = output + *count;
+ char *p = output;
+ char *end = output + *count;
while (p < end) {
if (*p == '\n' || *p == '\r' || *p == TAB || *p == BELL) {
msg_putchar_attr((uint8_t)(*p), 0);
@@ -1141,7 +1142,7 @@ static void out_data_append_to_screen(char *output, size_t *count, bool eof)
goto end;
}
- (void)msg_outtrans_len(p, i, 0);
+ msg_outtrans_len(p, i, 0);
p += i;
}
}
@@ -1235,7 +1236,8 @@ static size_t word_length(const char *str)
/// before we finish writing.
static void read_input(DynamicBuffer *buf)
{
- size_t written = 0, len = 0;
+ size_t written = 0;
+ size_t len = 0;
linenr_T lnum = curbuf->b_op_start.lnum;
char *lp = ml_get(lnum);
diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c
index c920cb655e..ecedf144e5 100644
--- a/src/nvim/os/signal.c
+++ b/src/nvim/os/signal.c
@@ -7,9 +7,11 @@
#endif
#include "nvim/autocmd.h"
+#include "nvim/autocmd_defs.h"
+#include "nvim/buffer_defs.h"
#include "nvim/eval.h"
+#include "nvim/event/defs.h"
#include "nvim/event/signal.h"
-#include "nvim/func_attr.h"
#include "nvim/globals.h"
#include "nvim/log.h"
#include "nvim/main.h"
diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c
index 7691aa5122..ede17bc7c8 100644
--- a/src/nvim/os/stdpaths.c
+++ b/src/nvim/os/stdpaths.c
@@ -4,13 +4,16 @@
#include "nvim/ascii_defs.h"
#include "nvim/fileio.h"
-#include "nvim/func_attr.h"
#include "nvim/globals.h"
#include "nvim/memory.h"
#include "nvim/os/os.h"
#include "nvim/os/stdpaths_defs.h"
#include "nvim/path.h"
+#ifdef INCLUDE_GENERATED_DECLARATIONS
+# include "os/stdpaths.c.generated.h"
+#endif
+
/// Names of the environment variables, mapped to XDGVarType values
static const char *xdg_env_vars[] = {
[kXDGConfigHome] = "XDG_CONFIG_HOME",
diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c
index 49b43af6c0..16118028b4 100644
--- a/src/nvim/os/time.c
+++ b/src/nvim/os/time.c
@@ -8,8 +8,8 @@
#include "auto/config.h"
#include "nvim/event/loop.h"
-#include "nvim/func_attr.h"
-#include "nvim/gettext.h"
+#include "nvim/event/multiqueue.h"
+#include "nvim/gettext_defs.h"
#include "nvim/globals.h"
#include "nvim/log.h"
#include "nvim/main.h"
@@ -19,7 +19,7 @@
#include "nvim/os/time.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
-# include "os/time.c.generated.h" // IWYU pragma: export
+# include "os/time.c.generated.h"
#endif
/// Gets a high-resolution (nanosecond), monotonically-increasing time relative
diff --git a/src/nvim/os/time.h b/src/nvim/os/time.h
index 2748ba6953..b4d82d8002 100644
--- a/src/nvim/os/time.h
+++ b/src/nvim/os/time.h
@@ -3,7 +3,7 @@
#include <stddef.h> // IWYU pragma: keep
#include <time.h> // IWYU pragma: keep
-#include "nvim/os/time_defs.h" // IWYU pragma: export
+#include "nvim/os/time_defs.h" // IWYU pragma: keep
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/time.h.generated.h"
diff --git a/src/nvim/os/tty.c b/src/nvim/os/tty.c
deleted file mode 100644
index e683b9383f..0000000000
--- a/src/nvim/os/tty.c
+++ /dev/null
@@ -1,49 +0,0 @@
-//
-// Terminal/console utils
-//
-
-#include "nvim/os/os.h" // IWYU pragma: keep (Windows)
-#include "nvim/os/tty.h"
-
-#ifdef INCLUDE_GENERATED_DECLARATIONS
-# include "os/tty.c.generated.h" // IWYU pragma: export
-#endif
-
-#ifdef MSWIN
-# if !defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING)
-# define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
-# endif
-/// Guesses the terminal-type. Calls SetConsoleMode() and uv_set_vterm_state()
-/// if appropriate.
-///
-/// @param[in,out] term Name of the guessed terminal, statically-allocated
-/// @param out_fd stdout file descriptor
-void os_tty_guess_term(const char **term, int out_fd)
-{
- bool conemu_ansi = strequal(os_getenv("ConEmuANSI"), "ON");
- bool vtp = false;
-
- HANDLE handle = (HANDLE)_get_osfhandle(out_fd);
- DWORD dwMode;
- if (handle != INVALID_HANDLE_VALUE && GetConsoleMode(handle, &dwMode)) {
- dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
- if (SetConsoleMode(handle, dwMode)) {
- vtp = true;
- }
- }
-
- if (*term == NULL) {
- if (vtp) {
- *term = "vtpcon";
- } else if (conemu_ansi) {
- *term = "conemu";
- } else {
- *term = "win32con";
- }
- }
-
- if (conemu_ansi) {
- uv_tty_set_vterm_state(UV_TTY_SUPPORTED);
- }
-}
-#endif
diff --git a/src/nvim/os/tty.h b/src/nvim/os/tty.h
deleted file mode 100644
index a24d875c05..0000000000
--- a/src/nvim/os/tty.h
+++ /dev/null
@@ -1,5 +0,0 @@
-#pragma once
-
-#ifdef INCLUDE_GENERATED_DECLARATIONS
-# include "os/tty.h.generated.h" // IWYU pragma: export
-#endif
diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c
index ae0994a73f..8886d6068d 100644
--- a/src/nvim/os/users.c
+++ b/src/nvim/os/users.c
@@ -9,8 +9,10 @@
#include "nvim/ascii_defs.h"
#include "nvim/cmdexpand_defs.h"
#include "nvim/garray.h"
+#include "nvim/garray_defs.h"
#include "nvim/memory.h"
#include "nvim/os/os.h"
+#include "nvim/os/os_defs.h"
#include "nvim/vim_defs.h"
#ifdef HAVE_PWD_FUNCS
# include <pwd.h>
@@ -22,6 +24,10 @@
# include "nvim/message.h"
#endif
+#ifdef INCLUDE_GENERATED_DECLARATIONS
+# include "os/users.c.generated.h"
+#endif
+
// All user names (for ~user completion as done by shell).
static garray_T ga_users = GA_EMPTY_INIT_VALUE;
@@ -186,7 +192,7 @@ void free_users(void)
/// Done only once and then cached.
static void init_users(void)
{
- static int lazy_init_done = false;
+ static bool lazy_init_done = false;
if (lazy_init_done) {
return;