refactor: format files with uncrustify #15663

This commit is contained in:
dundargoc 2021-09-14 18:13:34 +02:00 committed by GitHub
parent 516775e9d8
commit 0a83017fe9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 440 additions and 512 deletions

View File

@ -1,4 +1,4 @@
# Uncrustify-0.73.0-162-ac9b0f48
# Uncrustify-0.73.0-164-c9a58467
#
# General options

View File

@ -2,14 +2,13 @@
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <assert.h>
#include <uv.h>
#include "nvim/event/libuv_process.h"
#include "nvim/event/loop.h"
#include "nvim/event/process.h"
#include "nvim/event/rstream.h"
#include "nvim/event/wstream.h"
#include "nvim/event/process.h"
#include "nvim/event/libuv_process.h"
#include "nvim/log.h"
#include "nvim/macros.h"
#include "nvim/os/os.h"
@ -68,7 +67,7 @@ int libuv_process_spawn(LibuvProcess *uvproc)
#ifdef WIN32
// pipe must be readable for IOCP to work on Windows.
uvproc->uvstdio[1].flags |= proc->overlapped ?
(UV_READABLE_PIPE | UV_OVERLAPPED_PIPE) : 0;
(UV_READABLE_PIPE | UV_OVERLAPPED_PIPE) : 0;
#endif
uvproc->uvstdio[1].data.stream = STRUCT_CAST(uv_stream_t,
&proc->out.uv.pipe);

View File

@ -3,7 +3,6 @@
#include <stdarg.h>
#include <stdint.h>
#include <uv.h>
#include "nvim/event/loop.h"

View File

@ -49,8 +49,6 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <uv.h>
#include "nvim/event/multiqueue.h"
@ -89,7 +87,7 @@ typedef struct {
# include "event/multiqueue.c.generated.h"
#endif
static Event NILEVENT = { .handler = NULL, .argv = {NULL} };
static Event NILEVENT = { .handler = NULL, .argv = { NULL } };
MultiQueue *multiqueue_new_parent(PutCallback put_cb, void *data)
{
@ -104,8 +102,7 @@ MultiQueue *multiqueue_new_child(MultiQueue *parent)
return multiqueue_new(parent, NULL, NULL);
}
static MultiQueue *multiqueue_new(MultiQueue *parent, PutCallback put_cb,
void *data)
static MultiQueue *multiqueue_new(MultiQueue *parent, PutCallback put_cb, void *data)
{
MultiQueue *rv = xmalloc(sizeof(MultiQueue));
QUEUE_INIT(&rv->headtail);

View File

@ -3,20 +3,19 @@
#include <assert.h>
#include <stdlib.h>
#include <uv.h>
#include "nvim/os/shell.h"
#include "nvim/event/libuv_process.h"
#include "nvim/event/loop.h"
#include "nvim/event/process.h"
#include "nvim/event/rstream.h"
#include "nvim/event/wstream.h"
#include "nvim/event/process.h"
#include "nvim/event/libuv_process.h"
#include "nvim/globals.h"
#include "nvim/log.h"
#include "nvim/macros.h"
#include "nvim/os/process.h"
#include "nvim/os/pty_process.h"
#include "nvim/globals.h"
#include "nvim/macros.h"
#include "nvim/log.h"
#include "nvim/os/shell.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/process.c.generated.h"
@ -62,14 +61,14 @@ int process_spawn(Process *proc, bool in, bool out, bool err)
int status;
switch (proc->type) {
case kProcessTypeUv:
status = libuv_process_spawn((LibuvProcess *)proc);
break;
case kProcessTypePty:
status = pty_process_spawn((PtyProcess *)proc);
break;
default:
abort();
case kProcessTypeUv:
status = libuv_process_spawn((LibuvProcess *)proc);
break;
case kProcessTypePty:
status = pty_process_spawn((PtyProcess *)proc);
break;
default:
abort();
}
if (status) {
@ -139,9 +138,8 @@ void process_teardown(Loop *loop) FUNC_ATTR_NONNULL_ALL
}
// Wait until all children exit and all close events are processed.
LOOP_PROCESS_EVENTS_UNTIL(
loop, loop->events, -1,
kl_empty(loop->children) && multiqueue_empty(loop->events));
LOOP_PROCESS_EVENTS_UNTIL(loop, loop->events, -1,
kl_empty(loop->children) && multiqueue_empty(loop->events));
pty_process_teardown(loop);
}
@ -189,7 +187,7 @@ int process_wait(Process *proc, int ms, MultiQueue *events)
// We can only return if all streams/handles are closed and the job
// exited.
LOOP_PROCESS_EVENTS_UNTIL(proc->loop, events, -1,
proc->refcount == 1);
proc->refcount == 1);
} else {
LOOP_PROCESS_EVENTS(proc->loop, events, 0);
}
@ -222,16 +220,16 @@ void process_stop(Process *proc) FUNC_ATTR_NONNULL_ALL
proc->exit_signal = SIGTERM;
switch (proc->type) {
case kProcessTypeUv:
os_proc_tree_kill(proc->pid, SIGTERM);
break;
case kProcessTypePty:
// close all streams for pty processes to send SIGHUP to the process
process_close_streams(proc);
pty_process_close_master((PtyProcess *)proc);
break;
default:
abort();
case kProcessTypeUv:
os_proc_tree_kill(proc->pid, SIGTERM);
break;
case kProcessTypePty:
// close all streams for pty processes to send SIGHUP to the process
process_close_streams(proc);
pty_process_close_master((PtyProcess *)proc);
break;
default:
abort();
}
// (Re)start timer to verify that stopped process(es) died.
@ -325,14 +323,14 @@ static void process_close(Process *proc)
}
switch (proc->type) {
case kProcessTypeUv:
libuv_process_close((LibuvProcess *)proc);
break;
case kProcessTypePty:
pty_process_close((PtyProcess *)proc);
break;
default:
abort();
case kProcessTypeUv:
libuv_process_close((LibuvProcess *)proc);
break;
case kProcessTypePty:
pty_process_close((PtyProcess *)proc);
break;
default:
abort();
}
}
@ -369,7 +367,7 @@ static void flush_stream(Process *proc, Stream *stream)
// Poll for data and process the generated events.
loop_poll_events(proc->loop, 0);
if (stream->events) {
multiqueue_process_events(stream->events);
multiqueue_process_events(stream->events);
}
// Stream can be closed if it is empty.

View File

@ -2,19 +2,18 @@
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <assert.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <uv.h>
#include "nvim/event/rstream.h"
#include "nvim/ascii.h"
#include "nvim/vim.h"
#include "nvim/memory.h"
#include "nvim/log.h"
#include "nvim/misc1.h"
#include "nvim/event/loop.h"
#include "nvim/event/rstream.h"
#include "nvim/log.h"
#include "nvim/memory.h"
#include "nvim/misc1.h"
#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/rstream.c.generated.h"
@ -160,14 +159,13 @@ static void fread_idle_cb(uv_idle_t *handle)
}
// Synchronous read
uv_fs_read(
handle->loop,
&req,
stream->fd,
&stream->uvbuf,
1,
(int64_t) stream->fpos,
NULL);
uv_fs_read(handle->loop,
&req,
stream->fd,
&stream->uvbuf,
1,
(int64_t)stream->fpos,
NULL);
uv_fs_req_cleanup(&req);
@ -178,7 +176,7 @@ static void fread_idle_cb(uv_idle_t *handle)
}
// no errors (req.result (ssize_t) is positive), it's safe to cast.
size_t nread = (size_t) req.result;
size_t nread = (size_t)req.result;
rbuffer_produced(stream->buffer, nread);
stream->fpos += nread;
invoke_read_cb(stream, nread, false);

View File

@ -3,30 +3,28 @@
#include <assert.h>
#include <stdint.h>
#include <uv.h>
#include "nvim/event/loop.h"
#include "nvim/event/socket.h"
#include "nvim/event/rstream.h"
#include "nvim/event/wstream.h"
#include "nvim/os/os.h"
#include "nvim/ascii.h"
#include "nvim/vim.h"
#include "nvim/strings.h"
#include "nvim/path.h"
#include "nvim/charset.h"
#include "nvim/event/loop.h"
#include "nvim/event/rstream.h"
#include "nvim/event/socket.h"
#include "nvim/event/wstream.h"
#include "nvim/log.h"
#include "nvim/macros.h"
#include "nvim/main.h"
#include "nvim/memory.h"
#include "nvim/macros.h"
#include "nvim/charset.h"
#include "nvim/log.h"
#include "nvim/os/os.h"
#include "nvim/path.h"
#include "nvim/strings.h"
#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/socket.c.generated.h"
#endif
int socket_watcher_init(Loop *loop, SocketWatcher *watcher,
const char *endpoint)
int socket_watcher_init(Loop *loop, SocketWatcher *watcher, const char *endpoint)
FUNC_ATTR_NONNULL_ALL
{
xstrlcpy(watcher->addr, endpoint, sizeof(watcher->addr));
@ -56,9 +54,9 @@ int socket_watcher_init(Loop *loop, SocketWatcher *watcher,
int retval = uv_getaddrinfo(&loop->uv, &request, NULL, addr, port,
&(struct addrinfo){
.ai_family = AF_UNSPEC,
.ai_socktype = SOCK_STREAM,
});
.ai_family = AF_UNSPEC,
.ai_socktype = SOCK_STREAM,
});
if (retval != 0) {
ELOG("Host lookup failed: %s", endpoint);
return retval;
@ -106,7 +104,7 @@ int socket_watcher_start(SocketWatcher *watcher, int backlog, socket_cb cb)
uv_tcp_getsockname(&watcher->uv.tcp.handle, (struct sockaddr *)&sas,
&(int){ sizeof(sas) });
uint16_t port = (uint16_t)(
(sas.ss_family == AF_INET)
(sas.ss_family == AF_INET)
? (STRUCT_CAST(struct sockaddr_in, &sas))->sin_port
: (STRUCT_CAST(struct sockaddr_in6, &sas))->sin6_port);
// v:servername uses the string from watcher->addr
@ -183,7 +181,7 @@ static void connection_cb(uv_stream_t *handle, int status)
{
SocketWatcher *watcher = handle->data;
CREATE_EVENT(watcher->events, connection_event, 2, watcher,
(void *)(uintptr_t)status);
(void *)(uintptr_t)status);
}
static void close_cb(uv_handle_t *handle)
@ -203,9 +201,8 @@ static void connect_cb(uv_connect_t *req, int status)
}
}
bool socket_connect(Loop *loop, Stream *stream,
bool is_tcp, const char *address,
int timeout, const char **error)
bool socket_connect(Loop *loop, Stream *stream, bool is_tcp, const char *address, int timeout,
const char **error)
{
bool success = false;
int status;
@ -243,7 +240,6 @@ tcp_retry:
uv_tcp_nodelay(tcp, true);
uv_tcp_connect(&req, tcp, addrinfo->ai_addr, connect_cb);
uv_stream = (uv_stream_t *)tcp;
} else {
uv_pipe_t *pipe = &stream->uv.pipe;
uv_pipe_init(&loop->uv, pipe, 0);

View File

@ -2,15 +2,14 @@
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <assert.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdio.h>
#include <uv.h>
#include "nvim/log.h"
#include "nvim/rbuffer.h"
#include "nvim/macros.h"
#include "nvim/event/stream.h"
#include "nvim/log.h"
#include "nvim/macros.h"
#include "nvim/rbuffer.h"
#ifdef WIN32
# include "nvim/os/os_win_console.h"
#endif
@ -77,7 +76,7 @@ void stream_init(Loop *loop, Stream *stream, int fd, uv_stream_t *uvstream)
uv_pipe_open(&stream->uv.pipe, fd);
stream->uvstream = STRUCT_CAST(uv_stream_t, &stream->uv.pipe);
#ifdef WIN32
}
}
#endif
}
}

View File

@ -2,7 +2,6 @@
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <stdint.h>
#include <uv.h>
#include "nvim/event/loop.h"
@ -23,8 +22,7 @@ void time_watcher_init(Loop *loop, TimeWatcher *watcher, void *data)
watcher->blockable = false;
}
void time_watcher_start(TimeWatcher *watcher, time_cb cb, uint64_t timeout,
uint64_t repeat)
void time_watcher_start(TimeWatcher *watcher, time_cb cb, uint64_t timeout, uint64_t repeat)
FUNC_ATTR_NONNULL_ALL
{
watcher->cb = cb;

View File

@ -2,17 +2,16 @@
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <assert.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <uv.h>
#include "nvim/log.h"
#include "nvim/event/loop.h"
#include "nvim/event/wstream.h"
#include "nvim/vim.h"
#include "nvim/log.h"
#include "nvim/memory.h"
#include "nvim/vim.h"
#define DEFAULT_MAXMEM 1024 * 1024 * 2000
@ -117,10 +116,7 @@ err:
/// @param cb Pointer to function that will be responsible for freeing
/// the buffer data(passing 'free' will work as expected).
/// @return The allocated WBuffer instance
WBuffer *wstream_new_buffer(char *data,
size_t size,
size_t refcount,
wbuffer_data_finalizer cb)
WBuffer *wstream_new_buffer(char *data, size_t size, size_t refcount, wbuffer_data_finalizer cb)
FUNC_ATTR_NONNULL_ARG(1)
{
WBuffer *rv = xmalloc(sizeof(WBuffer));

View File

@ -7,10 +7,10 @@
#include <stdint.h>
#include <uv.h>
#include "nvim/os/dl.h"
#include "nvim/os/os.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/os/dl.h"
#include "nvim/os/os.h"
/// possible function prototypes that can be called by os_libcall()
/// int -> int
@ -38,12 +38,8 @@ typedef int (*int_int_fn)(int i);
/// not NULL. NULL when using `int_out`.
/// @param[out] int_out the output integer param
/// @return true on success, false on failure
bool os_libcall(const char *libname,
const char *funcname,
const char *argv,
int argi,
char **str_out,
int *int_out)
bool os_libcall(const char *libname, const char *funcname, const char *argv, int argi,
char **str_out, int *int_out)
{
if (!libname || !funcname) {
return false;
@ -53,17 +49,17 @@ bool os_libcall(const char *libname,
// open the dynamic loadable library
if (uv_dlopen(libname, &lib)) {
EMSG2(_("dlerror = \"%s\""), uv_dlerror(&lib));
uv_dlclose(&lib);
return false;
EMSG2(_("dlerror = \"%s\""), uv_dlerror(&lib));
uv_dlclose(&lib);
return false;
}
// find and load the requested function in the library
gen_fn fn;
if (uv_dlsym(&lib, funcname, (void **) &fn)) {
EMSG2(_("dlerror = \"%s\""), uv_dlerror(&lib));
uv_dlclose(&lib);
return false;
if (uv_dlsym(&lib, funcname, (void **)&fn)) {
EMSG2(_("dlerror = \"%s\""), uv_dlerror(&lib));
uv_dlclose(&lib);
return false;
}
// call the library and save the result
@ -71,17 +67,17 @@ bool os_libcall(const char *libname,
// exceptions. jmp's on Unix seem to interact trickily with signals as
// well. So for now we only support those libraries that are well-behaved.
if (str_out) {
str_str_fn sfn = (str_str_fn) fn;
int_str_fn ifn = (int_str_fn) fn;
str_str_fn sfn = (str_str_fn)fn;
int_str_fn ifn = (int_str_fn)fn;
const char *res = argv ? sfn(argv) : ifn(argi);
// assume that ptr values of NULL, 1 or -1 are illegal
*str_out = (res && (intptr_t) res != 1 && (intptr_t) res != -1)
*str_out = (res && (intptr_t)res != 1 && (intptr_t)res != -1)
? xstrdup(res) : NULL;
} else {
str_int_fn sfn = (str_int_fn) fn;
int_int_fn ifn = (int_int_fn) fn;
str_int_fn sfn = (str_int_fn)fn;
int_int_fn ifn = (int_int_fn)fn;
*int_out = argv ? sfn(argv) : ifn(argi);
}

View File

@ -6,20 +6,20 @@
#include <assert.h>
#include <uv.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/charset.h"
#include "nvim/fileio.h"
#include "nvim/os/os.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/path.h"
#include "nvim/macros.h"
#include "nvim/strings.h"
#include "nvim/eval.h"
#include "nvim/ex_getln.h"
#include "nvim/version.h"
#include "nvim/fileio.h"
#include "nvim/macros.h"
#include "nvim/map.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/os/os.h"
#include "nvim/path.h"
#include "nvim/strings.h"
#include "nvim/version.h"
#include "nvim/vim.h"
#ifdef WIN32
#include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8
@ -206,7 +206,7 @@ size_t os_get_fullenv_size(void)
# if defined(HAVE__NSGETENVIRON)
char **environ = *_NSGetEnviron();
# else
extern char **environ;
extern char **environ;
# endif
while (environ[len] != NULL) {
@ -219,7 +219,9 @@ size_t os_get_fullenv_size(void)
void os_free_fullenv(char **env)
{
if (!env) { return; }
if (!env) {
return;
}
for (char **it = env; *it; it++) {
XFREE_CLEAR(*it);
}
@ -262,7 +264,7 @@ void os_copy_fullenv(char **env, size_t env_size)
# if defined(HAVE__NSGETENVIRON)
char **environ = *_NSGetEnviron();
# else
extern char **environ;
extern char **environ;
# endif
for (size_t i = 0; i < env_size && environ[i] != NULL; i++) {
@ -322,7 +324,7 @@ char *os_getenvname_at_index(size_t index)
# if defined(HAVE__NSGETENVIRON)
char **environ = *_NSGetEnviron();
# else
extern char **environ;
extern char **environ;
# endif
// check if index is inside the environ array
@ -566,16 +568,12 @@ void expand_env(char_u *src, char_u *dst, int dstlen)
/// @param esc Escape spaces in expanded variables
/// @param one `srcp` is a single filename
/// @param prefix Start again after this (can be NULL)
void expand_env_esc(char_u *restrict srcp,
char_u *restrict dst,
int dstlen,
bool esc,
bool one,
void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, bool esc, bool one,
char_u *prefix)
FUNC_ATTR_NONNULL_ARG(1, 2)
{
char_u *tail;
char_u *var;
char_u *tail;
char_u *var;
bool copy_char;
bool mustfree; // var was allocated, need to free it later
bool at_start = true; // at start of a name
@ -621,7 +619,7 @@ void expand_env_esc(char_u *restrict srcp,
while (c-- > 0 && *tail != NUL && *tail != '}') {
*var++ = *tail++;
}
} else // NOLINT
} else // NOLINT
#endif
{
while (c-- > 0 && *tail != NUL && vim_isIDc(*tail)) {
@ -642,7 +640,7 @@ void expand_env_esc(char_u *restrict srcp,
var = (char_u *)vim_getenv((char *)dst);
mustfree = true;
#if defined(UNIX)
}
}
#endif
} else if (src[1] == NUL // home directory
|| vim_ispathsep(src[1])
@ -673,7 +671,7 @@ void expand_env_esc(char_u *restrict srcp,
ExpandInit(&xpc);
xpc.xp_context = EXPAND_FILES;
var = ExpandOne(&xpc, dst, NULL,
WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE);
WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE);
mustfree = true;
}
#else
@ -687,7 +685,7 @@ void expand_env_esc(char_u *restrict srcp,
// If 'shellslash' is set change backslashes to forward slashes.
// Can't use slash_adjust(), p_ssl may be set temporarily.
if (p_ssl && var != NULL && vim_strchr(var, '\\') != NULL) {
char_u *p = vim_strsave(var);
char_u *p = vim_strsave(var);
if (mustfree) {
xfree(var);
@ -701,7 +699,7 @@ void expand_env_esc(char_u *restrict srcp,
// If "var" contains white space, escape it with a backslash.
// Required for ":e ~/tt" when $HOME includes a space.
if (esc && var != NULL && vim_strpbrk(var, (char_u *)" \t") != NULL) {
char_u *p = vim_strsave_escaped(var, (char_u *)" \t");
char_u *p = vim_strsave_escaped(var, (char_u *)" \t");
if (mustfree) {
xfree(var);
@ -721,8 +719,9 @@ void expand_env_esc(char_u *restrict srcp,
#if defined(BACKSLASH_IN_FILENAME)
&& dst[-1] != ':'
#endif
&& vim_ispathsep(*tail))
&& vim_ispathsep(*tail)) {
++tail;
}
dst += c;
src = tail;
copy_char = false;
@ -826,14 +825,11 @@ static char *remove_tail(char *path, char *pend, char *dirname)
/// @param[out] len Location where current directory length should be saved.
///
/// @return Next iter argument value or NULL when iteration should stop.
const void *vim_env_iter(const char delim,
const char *const val,
const void *const iter,
const char **const dir,
size_t *const len)
const void *vim_env_iter(const char delim, const char *const val, const void *const iter,
const char **const dir, size_t *const len)
FUNC_ATTR_NONNULL_ARG(2, 4, 5) FUNC_ATTR_WARN_UNUSED_RESULT
{
const char *varval = (const char *) iter;
const char *varval = (const char *)iter;
if (varval == NULL) {
varval = val;
}
@ -843,7 +839,7 @@ const void *vim_env_iter(const char delim,
*len = strlen(varval);
return NULL;
} else {
*len = (size_t) (dirend - varval);
*len = (size_t)(dirend - varval);
return dirend + 1;
}
}
@ -861,14 +857,11 @@ const void *vim_env_iter(const char delim,
/// @param[out] len Location where current directory length should be saved.
///
/// @return Next iter argument value or NULL when iteration should stop.
const void *vim_env_iter_rev(const char delim,
const char *const val,
const void *const iter,
const char **const dir,
size_t *const len)
const void *vim_env_iter_rev(const char delim, const char *const val, const void *const iter,
const char **const dir, size_t *const len)
FUNC_ATTR_NONNULL_ARG(2, 4, 5) FUNC_ATTR_WARN_UNUSED_RESULT
{
const char *varend = (const char *) iter;
const char *varend = (const char *)iter;
if (varend == NULL) {
varend = val + strlen(val) - 1;
}
@ -880,7 +873,7 @@ const void *vim_env_iter_rev(const char delim,
return NULL;
} else {
*dir = colon + 1;
*len = (size_t) (varend - colon);
*len = (size_t)(varend - colon);
return colon - 1;
}
}
@ -955,10 +948,9 @@ char *vim_getenv(const char *name)
// Find runtime path relative to the nvim binary: ../share/nvim/runtime
if (vim_path == NULL) {
vim_get_prefix_from_exepath(exe_name);
if (append_path(
exe_name,
"share" _PATHSEPSTR "nvim" _PATHSEPSTR "runtime" _PATHSEPSTR,
MAXPATHL) == OK) {
if (append_path(exe_name,
"share" _PATHSEPSTR "nvim" _PATHSEPSTR "runtime" _PATHSEPSTR,
MAXPATHL) == OK) {
vim_path = exe_name; // -V507
}
}
@ -1043,8 +1035,8 @@ char *vim_getenv(const char *name)
/// a list of them.
///
/// @return length of the string put into dst, does not include NUL byte.
size_t home_replace(const buf_T *const buf, const char_u *src,
char_u *const dst, size_t dstlen, const bool one)
size_t home_replace(const buf_T *const buf, const char_u *src, char_u *const dst, size_t dstlen,
const bool one)
FUNC_ATTR_NONNULL_ARG(3)
{
size_t dirlen = 0;

View File

@ -8,9 +8,9 @@
/// replacement.
#include <assert.h>
#include <stddef.h>
#include <stdbool.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stddef.h>
#include "auto/config.h"
@ -20,13 +20,13 @@
#include <uv.h>
#include "nvim/os/fileio.h"
#include "nvim/memory.h"
#include "nvim/os/os.h"
#include "nvim/globals.h"
#include "nvim/rbuffer.h"
#include "nvim/macros.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/os/fileio.h"
#include "nvim/os/os.h"
#include "nvim/rbuffer.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/fileio.c.generated.h"
@ -44,8 +44,8 @@
/// does not have kFileCreate\*).
///
/// @return Error code, or 0 on success. @see os_strerror()
int file_open(FileDescriptor *const ret_fp, const char *const fname,
const int flags, const int mode)
int file_open(FileDescriptor *const ret_fp, const char *const fname, const int flags,
const int mode)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
int os_open_flags = 0;
@ -99,8 +99,7 @@ int file_open(FileDescriptor *const ret_fp, const char *const fname,
/// FILE_WRITE_ONLY or FILE_READ_ONLY is required.
///
/// @return Error code (@see os_strerror()) or 0. Currently always returns 0.
int file_open_fd(FileDescriptor *const ret_fp, const int fd,
const int flags)
int file_open_fd(FileDescriptor *const ret_fp, const int fd, const int flags)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
ret_fp->wr = !!(flags & (kFileCreate
@ -131,8 +130,8 @@ int file_open_fd(FileDescriptor *const ret_fp, const int fd,
/// 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)
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));
@ -152,8 +151,7 @@ FileDescriptor *file_open_new(int *const error, const char *const fname,
/// 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)
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));
@ -277,8 +275,7 @@ static void file_rb_write_full_cb(RBuffer *const rv, FileDescriptor *const fp)
/// bytes.
///
/// @return error_code (< 0) or number of bytes read.
ptrdiff_t file_read(FileDescriptor *const fp, char *const ret_buf,
const size_t size)
ptrdiff_t file_read(FileDescriptor *const fp, char *const ret_buf, const size_t size)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
assert(!fp->wr);
@ -362,8 +359,7 @@ ptrdiff_t file_read(FileDescriptor *const fp, char *const ret_buf,
/// @param[in] size Amount of bytes to write.
///
/// @return Number of bytes written or libuv error code (< 0).
ptrdiff_t file_write(FileDescriptor *const fp, const char *const buf,
const size_t size)
ptrdiff_t file_write(FileDescriptor *const fp, const char *const buf, const size_t size)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1)
{
assert(fp->wr);
@ -392,8 +388,8 @@ ptrdiff_t file_skip(FileDescriptor *const fp, const size_t size)
assert(!fp->wr);
size_t read_bytes = 0;
do {
const ptrdiff_t new_read_bytes = file_read(
fp, skipbuf, MIN(size - read_bytes, sizeof(skipbuf)));
const ptrdiff_t new_read_bytes =
file_read(fp, skipbuf, MIN(size - read_bytes, sizeof(skipbuf)));
if (new_read_bytes < 0) {
return new_read_bytes;
} else if (new_read_bytes == 0) {

View File

@ -2,12 +2,12 @@
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
// fs.c -- filesystem access
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <assert.h>
#include <limits.h>
#include <fcntl.h>
#include <errno.h>
#include "auto/config.h"
@ -17,14 +17,14 @@
#include <uv.h>
#include "nvim/os/os.h"
#include "nvim/os/os_defs.h"
#include "nvim/ascii.h"
#include "nvim/assert.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/assert.h"
#include "nvim/misc1.h"
#include "nvim/option.h"
#include "nvim/os/os.h"
#include "nvim/os/os_defs.h"
#include "nvim/path.h"
#include "nvim/strings.h"
@ -37,18 +37,18 @@
#endif
#define RUN_UV_FS_FUNC(ret, func, ...) \
do { \
bool did_try_to_free = false; \
do { \
bool did_try_to_free = false; \
uv_call_start: {} \
uv_fs_t req; \
ret = func(&fs_loop, &req, __VA_ARGS__); \
uv_fs_req_cleanup(&req); \
if (ret == UV_ENOMEM && !did_try_to_free) { \
try_to_free_memory(); \
did_try_to_free = true; \
goto uv_call_start; \
} \
} while (0)
uv_fs_t req; \
ret = func(&fs_loop, &req, __VA_ARGS__); \
uv_fs_req_cleanup(&req); \
if (ret == UV_ENOMEM && !did_try_to_free) { \
try_to_free_memory(); \
did_try_to_free = true; \
goto uv_call_start; \
} \
} while (0)
// Many fs functions from libuv return that value on success.
static const int kLibuvSuccess = 0;
@ -199,16 +199,16 @@ int os_nodetype(const char *name)
}
switch (guess) {
case UV_TTY: // FILE_TYPE_CHAR
return NODE_WRITABLE;
case UV_FILE: // FILE_TYPE_DISK
return NODE_NORMAL;
case UV_NAMED_PIPE: // not handled explicitly in Vim os_win32.c
case UV_UDP: // unix only
case UV_TCP: // unix only
case UV_UNKNOWN_HANDLE:
default:
return NODE_OTHER; // Vim os_win32.c default
case UV_TTY: // FILE_TYPE_CHAR
return NODE_WRITABLE;
case UV_FILE: // FILE_TYPE_DISK
return NODE_NORMAL;
case UV_NAMED_PIPE: // not handled explicitly in Vim os_win32.c
case UV_UDP: // unix only
case UV_TCP: // unix only
case UV_UNKNOWN_HANDLE:
default:
return NODE_OTHER; // Vim os_win32.c default
}
#endif
}
@ -326,7 +326,7 @@ static bool is_executable_ext(const char *name, char **abspath)
sizeof(os_buf) - (size_t)(buf_end - os_buf), ENV_SEPSTR);
if (ext_len != 0) {
bool in_pathext = nameext_len == ext_len
&& 0 == mb_strnicmp((char_u *)nameext, (char_u *)ext, ext_len);
&& 0 == mb_strnicmp((char_u *)nameext, (char_u *)ext, ext_len);
if (((in_pathext || is_unix_shell) && is_executable(name, abspath))
|| is_executable(os_buf, abspath)) {
@ -436,17 +436,17 @@ FILE *os_fopen(const char *path, const char *flags)
// Per table in fopen(3) manpage.
if (flags[1] == '\0' || flags[1] == 'b') {
switch (flags[0]) {
case 'r':
iflags = O_RDONLY;
break;
case 'w':
iflags = O_WRONLY | O_CREAT | O_TRUNC;
break;
case 'a':
iflags = O_WRONLY | O_CREAT | O_APPEND;
break;
default:
abort();
case 'r':
iflags = O_RDONLY;
break;
case 'w':
iflags = O_WRONLY | O_CREAT | O_TRUNC;
break;
case 'a':
iflags = O_WRONLY | O_CREAT | O_APPEND;
break;
default:
abort();
}
#ifdef WIN32
if (flags[1] == 'b') {
@ -458,17 +458,17 @@ FILE *os_fopen(const char *path, const char *flags)
// char 1 is always '+' ('b' is handled above).
assert(flags[1] == '+');
switch (flags[0]) {
case 'r':
iflags = O_RDWR;
break;
case 'w':
iflags = O_RDWR | O_CREAT | O_TRUNC;
break;
case 'a':
iflags = O_RDWR | O_CREAT | O_APPEND;
break;
default:
abort();
case 'r':
iflags = O_RDWR;
break;
case 'w':
iflags = O_RDWR | O_CREAT | O_TRUNC;
break;
case 'a':
iflags = O_RDWR | O_CREAT | O_APPEND;
break;
default:
abort();
}
}
// Per fopen(3) manpage: default to 0666, it will be umask-adjusted.
@ -553,8 +553,8 @@ os_dup_dup:
/// @param[in] non_blocking Do not restart syscall if EAGAIN was encountered.
///
/// @return Number of bytes read or libuv error code (< 0).
ptrdiff_t os_read(const int fd, bool *const ret_eof, char *const ret_buf,
const size_t size, const bool non_blocking)
ptrdiff_t os_read(const int fd, bool *const ret_eof, char *const ret_buf, const size_t size,
const bool non_blocking)
FUNC_ATTR_WARN_UNUSED_RESULT
{
*ret_eof = false;
@ -609,8 +609,8 @@ ptrdiff_t os_read(const int fd, bool *const ret_eof, char *const ret_buf,
/// @param[in] non_blocking Do not restart syscall if EAGAIN was encountered.
///
/// @return Number of bytes read or libuv error code (< 0).
ptrdiff_t os_readv(const int fd, bool *const ret_eof, struct iovec *iov,
size_t iov_size, const bool non_blocking)
ptrdiff_t os_readv(const int fd, bool *const ret_eof, struct iovec *iov, size_t iov_size,
const bool non_blocking)
FUNC_ATTR_NONNULL_ALL
{
*ret_eof = false;
@ -668,8 +668,7 @@ ptrdiff_t os_readv(const int fd, bool *const ret_eof, struct iovec *iov,
/// @param[in] non_blocking Do not restart syscall if EAGAIN was encountered.
///
/// @return Number of bytes written or libuv error code (< 0).
ptrdiff_t os_write(const int fd, const char *const buf, const size_t size,
const bool non_blocking)
ptrdiff_t os_write(const int fd, const char *const buf, const size_t size, const bool non_blocking)
FUNC_ATTR_WARN_UNUSED_RESULT
{
if (buf == NULL) {
@ -884,8 +883,7 @@ int os_mkdir(const char *path, int32_t mode)
/// of the higher level directories.
///
/// @return `0` for success, libuv error code for failure.
int os_mkdir_recurse(const char *const dir, int32_t mode,
char **const failed_dir)
int os_mkdir_recurse(const char *const dir, int32_t mode, char **const failed_dir)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
// Get end of directory name in "dir".
@ -1058,8 +1056,7 @@ bool os_fileinfo_fd(int file_descriptor, FileInfo *file_info)
/// Compare the inodes of two FileInfos
///
/// @return `true` if the two FileInfos represent the same file.
bool os_fileinfo_id_equal(const FileInfo *file_info_1,
const FileInfo *file_info_2)
bool os_fileinfo_id_equal(const FileInfo *file_info_1, const FileInfo *file_info_2)
FUNC_ATTR_NONNULL_ALL
{
return file_info_1->stat.st_ino == file_info_2->stat.st_ino
@ -1149,8 +1146,7 @@ bool os_fileid_equal(const FileID *file_id_1, const FileID *file_id_2)
/// @param file_id Pointer to a `FileID`
/// @param file_info Pointer to a `FileInfo`
/// @return `true` if the `FileID` and the `FileInfo` represent te same file.
bool os_fileid_equal_fileinfo(const FileID *file_id,
const FileInfo *file_info)
bool os_fileid_equal_fileinfo(const FileID *file_id, const FileInfo *file_info)
FUNC_ATTR_NONNULL_ALL
{
return file_id->inode == file_info->stat.st_ino
@ -1219,8 +1215,7 @@ char *os_resolve_shortcut(const char *fname)
EMSG2("utf8_to_utf16 failed: %d", r);
} else if (p != NULL) {
// Get a pointer to the IPersistFile interface.
hr = pslw->lpVtbl->QueryInterface(
pslw, &IID_IPersistFile, (void **)&ppf);
hr = pslw->lpVtbl->QueryInterface(pslw, &IID_IPersistFile, (void **)&ppf);
if (hr != S_OK) {
goto shortcut_errorw;
}

View File

@ -2,28 +2,27 @@
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <assert.h>
#include <string.h>
#include <stdbool.h>
#include <string.h>
#include <uv.h>
#include "nvim/api/private/defs.h"
#include "nvim/os/input.h"
#include "nvim/ascii.h"
#include "nvim/event/loop.h"
#include "nvim/event/rstream.h"
#include "nvim/ascii.h"
#include "nvim/vim.h"
#include "nvim/ui.h"
#include "nvim/memory.h"
#include "nvim/keymap.h"
#include "nvim/mbyte.h"
#include "nvim/fileio.h"
#include "nvim/ex_cmds2.h"
#include "nvim/fileio.h"
#include "nvim/getchar.h"
#include "nvim/keymap.h"
#include "nvim/main.h"
#include "nvim/mbyte.h"
#include "nvim/memory.h"
#include "nvim/misc1.h"
#include "nvim/state.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/os/input.h"
#include "nvim/state.h"
#include "nvim/ui.h"
#include "nvim/vim.h"
#define READ_BUFFER_SIZE 0xfff
#define INPUT_BUFFER_SIZE (READ_BUFFER_SIZE * 4)
@ -102,8 +101,7 @@ static void create_cursorhold_event(bool events_enabled)
///
/// 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)
int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt, MultiQueue *events)
{
if (maxlen && rbuffer_size(input_buffer)) {
return (int)rbuffer_read(input_buffer, (char *)buf, (size_t)maxlen);
@ -192,7 +190,7 @@ void os_breakcheck(void)
/// @return `true` if file descriptor refers to a terminal.
bool os_isatty(int fd)
{
return uv_guess_handle(fd) == UV_TTY;
return uv_guess_handle(fd) == UV_TTY;
}
size_t input_enqueue(String keys)
@ -208,8 +206,8 @@ size_t input_enqueue(String keys)
// K_SPECIAL(0x80) or CSI(0x9B).
uint8_t buf[19] = { 0 };
unsigned int new_size
= trans_special((const uint8_t **)&ptr, (size_t)(end - ptr), buf, true,
false);
= trans_special((const uint8_t **)&ptr, (size_t)(end - ptr), buf, true,
false);
if (new_size) {
new_size = handle_mouse_event(&ptr, buf, new_size);
@ -234,13 +232,13 @@ size_t input_enqueue(String keys)
// copy the character, escaping CSI and K_SPECIAL
if ((uint8_t)*ptr == CSI) {
rbuffer_write(input_buffer, (char *)&(uint8_t){K_SPECIAL}, 1);
rbuffer_write(input_buffer, (char *)&(uint8_t){KS_EXTRA}, 1);
rbuffer_write(input_buffer, (char *)&(uint8_t){KE_CSI}, 1);
rbuffer_write(input_buffer, (char *)&(uint8_t){ K_SPECIAL }, 1);
rbuffer_write(input_buffer, (char *)&(uint8_t){ KS_EXTRA }, 1);
rbuffer_write(input_buffer, (char *)&(uint8_t){ KE_CSI }, 1);
} else if ((uint8_t)*ptr == K_SPECIAL) {
rbuffer_write(input_buffer, (char *)&(uint8_t){K_SPECIAL}, 1);
rbuffer_write(input_buffer, (char *)&(uint8_t){KS_SPECIAL}, 1);
rbuffer_write(input_buffer, (char *)&(uint8_t){KE_FILLER}, 1);
rbuffer_write(input_buffer, (char *)&(uint8_t){ K_SPECIAL }, 1);
rbuffer_write(input_buffer, (char *)&(uint8_t){ KS_SPECIAL }, 1);
rbuffer_write(input_buffer, (char *)&(uint8_t){ KE_FILLER }, 1);
} else {
rbuffer_write(input_buffer, ptr, 1);
}
@ -301,8 +299,7 @@ static uint8_t check_multiclick(int code, int grid, int row, int col)
// Mouse event handling code(Extract row/col if available and detect multiple
// clicks)
static unsigned int handle_mouse_event(char **ptr, uint8_t *buf,
unsigned int bufsize)
static unsigned int handle_mouse_event(char **ptr, uint8_t *buf, unsigned int bufsize)
{
int mouse_code = 0;
int type = 0;
@ -318,7 +315,7 @@ static unsigned int handle_mouse_event(char **ptr, uint8_t *buf,
if (type != KS_EXTRA
|| !((mouse_code >= KE_LEFTMOUSE && mouse_code <= KE_RIGHTRELEASE)
|| (mouse_code >= KE_MOUSEDOWN && mouse_code <= KE_MOUSERIGHT))) {
|| (mouse_code >= KE_MOUSEDOWN && mouse_code <= KE_MOUSERIGHT))) {
return bufsize;
}
@ -364,8 +361,7 @@ static unsigned int handle_mouse_event(char **ptr, uint8_t *buf,
return bufsize;
}
size_t input_enqueue_mouse(int code, uint8_t modifier,
int grid, int row, int col)
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;
@ -437,8 +433,7 @@ bool input_available(void)
return rbuffer_size(input_buffer) != 0;
}
static void input_read_cb(Stream *stream, RBuffer *buf, size_t c, void *data,
bool at_eof)
static void input_read_cb(Stream *stream, RBuffer *buf, size_t c, void *data, bool at_eof)
{
if (at_eof) {
input_done();

View File

@ -1,9 +1,9 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "nvim/vim.h"
#include "nvim/os/input.h"
#include "nvim/os/os_win_console.h"
#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/os_win_console.c.generated.h"

View File

@ -23,16 +23,16 @@
#endif
#if defined(__APPLE__) || defined(BSD)
# include <sys/sysctl.h>
# include <pwd.h>
# include <sys/sysctl.h>
#endif
#include "nvim/api/private/helpers.h"
#include "nvim/globals.h"
#include "nvim/log.h"
#include "nvim/os/process.h"
#include "nvim/os/os.h"
#include "nvim/os/os_defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/os/process.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/process.c.generated.h"

View File

@ -3,9 +3,9 @@
#include <uv.h>
#include "nvim/vim.h"
#include "nvim/os/os.h"
#include "nvim/os/pty_conpty_win.h"
#include "nvim/vim.h"
#ifndef EXTENDED_STARTUPINFO_PRESENT
# define EXTENDED_STARTUPINFO_PRESENT 0x00080000
@ -54,8 +54,7 @@ TriState os_dyn_conpty_init(void)
return kTrue;
}
conpty_t *os_conpty_init(char **in_name, char **out_name,
uint16_t width, uint16_t height)
conpty_t *os_conpty_init(char **in_name, char **out_name, uint16_t width, uint16_t height)
{
static int count = 0;
conpty_t *conpty_object = xcalloc(1, sizeof(*conpty_object));
@ -65,36 +64,34 @@ conpty_t *os_conpty_init(char **in_name, char **out_name,
char buf[MAXPATHL];
SECURITY_ATTRIBUTES sa = { 0 };
const DWORD mode = PIPE_ACCESS_INBOUND
| PIPE_ACCESS_OUTBOUND | FILE_FLAG_FIRST_PIPE_INSTANCE;
| PIPE_ACCESS_OUTBOUND | FILE_FLAG_FIRST_PIPE_INSTANCE;
sa.nLength = sizeof(sa);
snprintf(buf, sizeof(buf), "\\\\.\\pipe\\nvim-term-in-%d-%d",
os_get_pid(), count);
*in_name = xstrdup(buf);
if ((in_read = CreateNamedPipeA(
*in_name,
mode,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
1,
0,
0,
30000,
&sa)) == INVALID_HANDLE_VALUE) {
if ((in_read = CreateNamedPipeA(*in_name,
mode,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
1,
0,
0,
30000,
&sa)) == INVALID_HANDLE_VALUE) {
emsg = "create input pipe failed";
goto failed;
}
snprintf(buf, sizeof(buf), "\\\\.\\pipe\\nvim-term-out-%d-%d",
os_get_pid(), count);
*out_name = xstrdup(buf);
if ((out_write = CreateNamedPipeA(
*out_name,
mode,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
1,
0,
0,
30000,
&sa)) == INVALID_HANDLE_VALUE) {
if ((out_write = CreateNamedPipeA(*out_name,
mode,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
1,
0,
0,
30000,
&sa)) == INVALID_HANDLE_VALUE) {
emsg = "create output pipe failed";
goto failed;
}
@ -113,22 +110,20 @@ conpty_t *os_conpty_init(char **in_name, char **out_name,
InitializeProcThreadAttributeList(NULL, 1, 0, & bytes_required);
conpty_object->si_ex.lpAttributeList =
(PPROC_THREAD_ATTRIBUTE_LIST)xmalloc(bytes_required);
if (!InitializeProcThreadAttributeList(
conpty_object->si_ex.lpAttributeList,
1,
0,
&bytes_required)) {
if (!InitializeProcThreadAttributeList(conpty_object->si_ex.lpAttributeList,
1,
0,
&bytes_required)) {
emsg = "InitializeProcThreadAttributeList failed";
goto failed;
}
if (!UpdateProcThreadAttribute(
conpty_object->si_ex.lpAttributeList,
0,
PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE,
conpty_object->pty,
sizeof(conpty_object->pty),
NULL,
NULL)) {
if (!UpdateProcThreadAttribute(conpty_object->si_ex.lpAttributeList,
0,
PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE,
conpty_object->pty,
sizeof(conpty_object->pty),
NULL,
NULL)) {
emsg = "UpdateProcThreadAttribute failed";
goto failed;
}
@ -150,38 +145,35 @@ finished:
return conpty_object;
}
bool os_conpty_spawn(conpty_t *conpty_object, HANDLE *process_handle,
wchar_t *name, wchar_t *cmd_line, wchar_t *cwd,
wchar_t *env)
bool os_conpty_spawn(conpty_t *conpty_object, HANDLE *process_handle, wchar_t *name,
wchar_t *cmd_line, wchar_t *cwd, wchar_t *env)
{
PROCESS_INFORMATION pi = { 0 };
if (!CreateProcessW(
name,
cmd_line,
NULL,
NULL,
false,
EXTENDED_STARTUPINFO_PRESENT | CREATE_UNICODE_ENVIRONMENT,
env,
cwd,
&conpty_object->si_ex.StartupInfo,
&pi)) {
if (!CreateProcessW(name,
cmd_line,
NULL,
NULL,
false,
EXTENDED_STARTUPINFO_PRESENT | CREATE_UNICODE_ENVIRONMENT,
env,
cwd,
&conpty_object->si_ex.StartupInfo,
&pi)) {
return false;
}
*process_handle = pi.hProcess;
return true;
}
void os_conpty_set_size(conpty_t *conpty_object,
uint16_t width, uint16_t height)
void os_conpty_set_size(conpty_t *conpty_object, uint16_t width, uint16_t height)
{
assert(width <= SHRT_MAX);
assert(height <= SHRT_MAX);
COORD size = { (int16_t)width, (int16_t)height };
if (pResizePseudoConsole(conpty_object->pty, size) != S_OK) {
ELOG("ResizePseudoConsoel failed: error code: %d",
os_translate_sys_error((int)GetLastError()));
}
assert(width <= SHRT_MAX);
assert(height <= SHRT_MAX);
COORD size = { (int16_t)width, (int16_t)height };
if (pResizePseudoConsole(conpty_object->pty, size) != S_OK) {
ELOG("ResizePseudoConsoel failed: error code: %d",
os_translate_sys_error((int)GetLastError()));
}
}
void os_conpty_free(conpty_t *conpty_object)

View File

@ -5,11 +5,10 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/ioctl.h>
#include <termios.h>
// forkpty is not in POSIX, so headers are platform-specific
#if defined(__FreeBSD__) || defined(__DragonFly__)
@ -26,15 +25,14 @@
#include <uv.h>
#include "nvim/lib/klist.h"
#include "nvim/event/loop.h"
#include "nvim/event/process.h"
#include "nvim/event/rstream.h"
#include "nvim/event/wstream.h"
#include "nvim/event/process.h"
#include "nvim/os/pty_process_unix.h"
#include "nvim/lib/klist.h"
#include "nvim/log.h"
#include "nvim/os/os.h"
#include "nvim/os/pty_process_unix.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/pty_process_unix.c.generated.h"

View File

@ -4,15 +4,14 @@
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <winpty_constants.h>
#include "nvim/os/os.h"
#include "nvim/ascii.h"
#include "nvim/memory.h"
#include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8
#include "nvim/os/pty_process_win.h"
#include "nvim/memory.h"
#include "nvim/os/os.h"
#include "nvim/os/pty_conpty_win.h"
#include "nvim/os/pty_process_win.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/pty_process_win.c.generated.h"
@ -59,8 +58,8 @@ int pty_process_spawn(PtyProcess *ptyproc)
if (os_has_conpty_working()) {
if ((conpty_object =
os_conpty_init(&in_name, &out_name,
ptyproc->width, ptyproc->height)) != NULL) {
os_conpty_init(&in_name, &out_name,
ptyproc->width, ptyproc->height)) != NULL) {
ptyproc->type = kConpty;
}
}
@ -94,20 +93,18 @@ int pty_process_spawn(PtyProcess *ptyproc)
if (!proc->in.closed) {
in_req = xmalloc(sizeof(uv_connect_t));
uv_pipe_connect(
in_req,
&proc->in.uv.pipe,
in_name,
pty_process_connect_cb);
uv_pipe_connect(in_req,
&proc->in.uv.pipe,
in_name,
pty_process_connect_cb);
}
if (!proc->out.closed) {
out_req = xmalloc(sizeof(uv_connect_t));
uv_pipe_connect(
out_req,
&proc->out.uv.pipe,
out_name,
pty_process_connect_cb);
uv_pipe_connect(out_req,
&proc->out.uv.pipe,
out_name,
pty_process_connect_cb);
}
if (proc->cwd != NULL) {
@ -146,13 +143,12 @@ int pty_process_spawn(PtyProcess *ptyproc)
goto cleanup;
}
} else {
spawncfg = winpty_spawn_config_new(
WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN,
NULL, // Optional application name
cmd_line,
cwd,
env,
&err);
spawncfg = winpty_spawn_config_new(WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN,
NULL, // Optional application name
cmd_line,
cwd,
env,
&err);
if (spawncfg == NULL) {
emsg = "winpty_spawn_config_new failed";
goto cleanup;
@ -176,13 +172,12 @@ int pty_process_spawn(PtyProcess *ptyproc)
}
proc->pid = (int)GetProcessId(process_handle);
if (!RegisterWaitForSingleObject(
&ptyproc->finish_wait,
process_handle,
pty_process_finish1,
ptyproc,
INFINITE,
WT_EXECUTEDEFAULT | WT_EXECUTEONLYONCE)) {
if (!RegisterWaitForSingleObject(&ptyproc->finish_wait,
process_handle,
pty_process_finish1,
ptyproc,
INFINITE,
WT_EXECUTEDEFAULT | WT_EXECUTEONLYONCE)) {
abort();
}
@ -193,8 +188,8 @@ int pty_process_spawn(PtyProcess *ptyproc)
}
(ptyproc->type == kConpty) ?
(void *)(ptyproc->object.conpty = conpty_object) :
(void *)(ptyproc->object.winpty = winpty_object);
(void *)(ptyproc->object.conpty = conpty_object) :
(void *)(ptyproc->object.winpty = winpty_object);
ptyproc->process_handle = process_handle;
winpty_object = NULL;
conpty_object = NULL;
@ -235,8 +230,7 @@ const char *pty_process_tty_name(PtyProcess *ptyproc)
return "?";
}
void pty_process_resize(PtyProcess *ptyproc, uint16_t width,
uint16_t height)
void pty_process_resize(PtyProcess *ptyproc, uint16_t width, uint16_t height)
FUNC_ATTR_NONNULL_ALL
{
if (ptyproc->type == kConpty
@ -454,15 +448,24 @@ int translate_winpty_error(int winpty_errno)
}
switch (winpty_errno) {
case WINPTY_ERROR_OUT_OF_MEMORY: return UV_ENOMEM;
case WINPTY_ERROR_SPAWN_CREATE_PROCESS_FAILED: return UV_EAI_FAIL;
case WINPTY_ERROR_LOST_CONNECTION: return UV_ENOTCONN;
case WINPTY_ERROR_AGENT_EXE_MISSING: return UV_ENOENT;
case WINPTY_ERROR_UNSPECIFIED: return UV_UNKNOWN;
case WINPTY_ERROR_AGENT_DIED: return UV_ESRCH;
case WINPTY_ERROR_AGENT_TIMEOUT: return UV_ETIMEDOUT;
case WINPTY_ERROR_AGENT_CREATION_FAILED: return UV_EAI_FAIL;
default: return UV_UNKNOWN;
case WINPTY_ERROR_OUT_OF_MEMORY:
return UV_ENOMEM;
case WINPTY_ERROR_SPAWN_CREATE_PROCESS_FAILED:
return UV_EAI_FAIL;
case WINPTY_ERROR_LOST_CONNECTION:
return UV_ENOTCONN;
case WINPTY_ERROR_AGENT_EXE_MISSING:
return UV_ENOENT;
case WINPTY_ERROR_UNSPECIFIED:
return UV_UNKNOWN;
case WINPTY_ERROR_AGENT_DIED:
return UV_ESRCH;
case WINPTY_ERROR_AGENT_TIMEOUT:
return UV_ETIMEDOUT;
case WINPTY_ERROR_AGENT_CREATION_FAILED:
return UV_EAI_FAIL;
default:
return UV_UNKNOWN;
}
}

View File

@ -1,36 +1,35 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <string.h>
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <uv.h>
#include "nvim/ascii.h"
#include "nvim/charset.h"
#include "nvim/event/libuv_process.h"
#include "nvim/event/loop.h"
#include "nvim/event/rstream.h"
#include "nvim/ex_cmds.h"
#include "nvim/fileio.h"
#include "nvim/lib/kvec.h"
#include "nvim/log.h"
#include "nvim/event/loop.h"
#include "nvim/event/libuv_process.h"
#include "nvim/event/rstream.h"
#include "nvim/ex_cmds.h"
#include "nvim/main.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/option_defs.h"
#include "nvim/os/shell.h"
#include "nvim/os/signal.h"
#include "nvim/path.h"
#include "nvim/types.h"
#include "nvim/main.h"
#include "nvim/vim.h"
#include "nvim/message.h"
#include "nvim/memory.h"
#include "nvim/ui.h"
#include "nvim/screen.h"
#include "nvim/memline.h"
#include "nvim/option_defs.h"
#include "nvim/charset.h"
#include "nvim/strings.h"
#include "nvim/types.h"
#include "nvim/ui.h"
#include "nvim/vim.h"
#define DYNAMIC_BUFFER_INIT { NULL, 0, 0 }
#define NS_1_SECOND 1000000000U // 1 second, in nanoseconds
@ -47,8 +46,7 @@ typedef struct {
# include "os/shell.c.generated.h"
#endif
static void save_patterns(int num_pat, char_u **pat, int *num_file,
char_u ***file)
static void save_patterns(int num_pat, char_u **pat, int *num_file, char_u ***file)
{
*file = xmalloc((size_t)num_pat * sizeof(char_u *));
for (int i = 0; i < num_pat; i++) {
@ -99,22 +97,21 @@ static bool have_dollars(int num, char_u **file)
/// copied into *file.
///
/// @returns OK for success or FAIL for error.
int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
char_u ***file, int flags)
int os_expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u ***file, int flags)
FUNC_ATTR_NONNULL_ARG(3)
FUNC_ATTR_NONNULL_ARG(4)
{
int i;
size_t len;
char_u *p;
char_u *p;
bool dir;
char_u *extra_shell_arg = NULL;
ShellOpts shellopts = kShellOptExpand | kShellOptSilent;
int j;
char_u *tempname;
char_u *command;
FILE *fd;
char_u *buffer;
char_u *tempname;
char_u *command;
FILE *fd;
char_u *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
@ -215,7 +212,7 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
}
if (is_fish_shell) {
len += sizeof("egin;"" end") - 1;
len += sizeof("egin;" " end") - 1;
}
command = xmalloc(len);
@ -319,9 +316,9 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
if (shell_style == STYLE_PRINT) {
extra_shell_arg = (char_u *)"-G"; // Use zsh NULL_GLOB option
// If we use -f then shell variables set in .cshrc won't get expanded.
// vi can do it, so we will too, but it is only necessary if there is a "$"
// in one of the patterns, otherwise we can still use the fast option.
// If we use -f then shell variables set in .cshrc won't get expanded.
// vi can do it, so we will too, but it is only necessary if there is a "$"
// in one of the patterns, otherwise we can still use the fast option.
} else if (shell_style == STYLE_GLOB && !have_dollars(num_pat, pat)) {
extra_shell_arg = (char_u *)"-f"; // Use csh fast option
}
@ -409,7 +406,7 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
}
p = skipwhite(p); // skip to next entry
}
// file names are separated with NL
// file names are separated with NL
} else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB) {
buffer[len] = NUL; // make sure the buffer ends in NUL
p = buffer;
@ -422,7 +419,7 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
}
p = skipwhite(p); // skip leading white space
}
// file names are separated with NUL
// file names are separated with NUL
} else {
// Some versions of zsh use spaces instead of NULs to separate
// results. Only do this when there is no NUL before the end of the
@ -705,22 +702,14 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_args)
/// returned buffer is not NULL)
/// @return the return code of the process, -1 if the process couldn't be
/// started properly
int os_system(char **argv,
const char *input,
size_t len,
char **output,
int os_system(char **argv, const char *input, size_t len, char **output,
size_t *nread) FUNC_ATTR_NONNULL_ARG(1)
{
return do_os_system(argv, input, len, output, nread, true, false);
}
static int do_os_system(char **argv,
const char *input,
size_t len,
char **output,
size_t *nread,
bool silent,
bool forward_output)
static int do_os_system(char **argv, const char *input, size_t len, char **output, size_t *nread,
bool silent, bool forward_output)
{
out_data_decide_throttle(0); // Initialize throttle decider.
out_data_ring(NULL, 0); // Initialize output ring-buffer.
@ -851,8 +840,7 @@ static void dynamic_buffer_ensure(DynamicBuffer *buf, size_t desired)
buf->data = xrealloc(buf->data, buf->cap);
}
static void system_data_cb(Stream *stream, RBuffer *buf, size_t count,
void *data, bool eof)
static void system_data_cb(Stream *stream, RBuffer *buf, size_t count, void *data, bool eof)
{
DynamicBuffer *dbuf = data;
@ -1015,8 +1003,7 @@ end:
ui_flush();
}
static void out_data_cb(Stream *stream, RBuffer *buf, size_t count, void *data,
bool eof)
static void out_data_cb(Stream *stream, RBuffer *buf, size_t count, void *data, bool eof)
{
size_t cnt;
char *ptr = rbuffer_read_ptr(buf, &cnt);
@ -1049,10 +1036,10 @@ static size_t tokenize(const char_u *const str, char **const argv)
FUNC_ATTR_NONNULL_ARG(1)
{
size_t argc = 0;
const char *p = (const char *) str;
const char *p = (const char *)str;
while (*p != NUL) {
const size_t len = word_length((const char_u *) p);
const size_t len = word_length((const char_u *)p);
if (argv != NULL) {
// Fill the slot
@ -1060,7 +1047,7 @@ static size_t tokenize(const char_u *const str, char **const argv)
}
argc++;
p = (const char *) skipwhite((char_u *) (p + len));
p = (const char *)skipwhite((char_u *)(p + len));
}
return argc;
@ -1115,7 +1102,7 @@ static void read_input(DynamicBuffer *buf)
dynamic_buffer_ensure(buf, buf->len + len);
buf->data[buf->len++] = NUL;
} else {
char_u *s = vim_strchr(lp + written, NL);
char_u *s = vim_strchr(lp + written, NL);
len = s == NULL ? l : (size_t)(s - (lp + written));
dynamic_buffer_ensure(buf, buf->len + len);
memcpy(buf->data + buf->len, lp + written, len);

View File

@ -3,25 +3,24 @@
#include <assert.h>
#include <stdbool.h>
#include <uv.h>
#ifndef WIN32
# include <signal.h> // for sigset_t
#endif
#include "nvim/ascii.h"
#include "nvim/log.h"
#include "nvim/vim.h"
#include "nvim/globals.h"
#include "nvim/memline.h"
#include "nvim/eval.h"
#include "nvim/event/loop.h"
#include "nvim/event/signal.h"
#include "nvim/fileio.h"
#include "nvim/globals.h"
#include "nvim/log.h"
#include "nvim/main.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/misc1.h"
#include "nvim/event/signal.h"
#include "nvim/os/signal.h"
#include "nvim/event/loop.h"
#include "nvim/vim.h"
static SignalWatcher spipe, shup, squit, sterm, susr1;
#ifdef SIGPWR
@ -124,27 +123,27 @@ static char * signal_name(int signum)
{
switch (signum) {
#ifdef SIGPWR
case SIGPWR:
return "SIGPWR";
case SIGPWR:
return "SIGPWR";
#endif
#ifdef SIGPIPE
case SIGPIPE:
return "SIGPIPE";
case SIGPIPE:
return "SIGPIPE";
#endif
case SIGTERM:
return "SIGTERM";
case SIGTERM:
return "SIGTERM";
#ifdef SIGQUIT
case SIGQUIT:
return "SIGQUIT";
case SIGQUIT:
return "SIGQUIT";
#endif
case SIGHUP:
return "SIGHUP";
case SIGHUP:
return "SIGHUP";
#ifdef SIGUSR1
case SIGUSR1:
return "SIGUSR1";
case SIGUSR1:
return "SIGUSR1";
#endif
default:
return "Unknown";
default:
return "Unknown";
}
}
@ -173,34 +172,34 @@ static void on_signal(SignalWatcher *handle, int signum, void *data)
assert(signum >= 0);
switch (signum) {
#ifdef SIGPWR
case SIGPWR:
// Signal of a power failure(eg batteries low), flush the swap files to
// be safe
ml_sync_all(false, false, true);
break;
case SIGPWR:
// Signal of a power failure(eg batteries low), flush the swap files to
// be safe
ml_sync_all(false, false, true);
break;
#endif
#ifdef SIGPIPE
case SIGPIPE:
// Ignore
break;
case SIGPIPE:
// Ignore
break;
#endif
case SIGTERM:
case SIGTERM:
#ifdef SIGQUIT
case SIGQUIT:
case SIGQUIT:
#endif
case SIGHUP:
if (!rejecting_deadly) {
deadly_signal(signum);
}
break;
case SIGHUP:
if (!rejecting_deadly) {
deadly_signal(signum);
}
break;
#ifdef SIGUSR1
case SIGUSR1:
apply_autocmds(EVENT_SIGNAL, (char_u *)"SIGUSR1", curbuf->b_fname, true,
curbuf);
break;
case SIGUSR1:
apply_autocmds(EVENT_SIGNAL, (char_u *)"SIGUSR1", curbuf->b_fname, true,
curbuf);
break;
#endif
default:
ELOG("invalid signal: %d", signum);
break;
default:
ELOG("invalid signal: %d", signum);
break;
}
}

View File

@ -3,11 +3,11 @@
#include <stdbool.h>
#include "nvim/os/stdpaths_defs.h"
#include "nvim/os/os.h"
#include "nvim/path.h"
#include "nvim/memory.h"
#include "nvim/ascii.h"
#include "nvim/memory.h"
#include "nvim/os/os.h"
#include "nvim/os/stdpaths_defs.h"
#include "nvim/path.h"
/// Names of the environment variables, mapped to XDGVarType values
static const char *xdg_env_vars[] = {
@ -137,8 +137,7 @@ char *stdpaths_user_conf_subpath(const char *fname)
/// @param[in] escape_commas If true, all commas will be escaped.
///
/// @return [allocated] `$XDG_DATA_HOME/nvim/{fname}`.
char *stdpaths_user_data_subpath(const char *fname,
const size_t trailing_pathseps,
char *stdpaths_user_data_subpath(const char *fname, const size_t trailing_pathseps,
const bool escape_commas)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET
{

View File

@ -3,15 +3,14 @@
#include <assert.h>
#include <limits.h>
#include <uv.h>
#include "nvim/assert.h"
#include "nvim/os/time.h"
#include "nvim/os/input.h"
#include "nvim/event/loop.h"
#include "nvim/os/os.h"
#include "nvim/main.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os/time.h"
static uv_mutex_t delay_mutex;
static uv_cond_t delay_cond;
@ -169,8 +168,7 @@ struct tm *os_localtime(struct tm *result) FUNC_ATTR_NONNULL_ALL
/// @param result[out] Pointer to a 'char' where the result should be placed
/// @param result_len length of result buffer
/// @return human-readable string of current local time
char *os_ctime_r(const time_t *restrict clock, char *restrict result,
size_t result_len)
char *os_ctime_r(const time_t *restrict clock, char *restrict result, size_t result_len)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET
{
struct tm clock_local;
@ -219,5 +217,5 @@ char *os_strptime(const char *str, const char *format, struct tm *tm)
Timestamp os_time(void)
FUNC_ATTR_WARN_UNUSED_RESULT
{
return (Timestamp) time(NULL);
return (Timestamp)time(NULL);
}

View File

@ -6,11 +6,10 @@
#include <uv.h>
#include "auto/config.h"
#include "nvim/ascii.h"
#include "nvim/os/os.h"
#include "nvim/garray.h"
#include "nvim/memory.h"
#include "nvim/os/os.h"
#include "nvim/strings.h"
#ifdef HAVE_PWD_H
# include <pwd.h>

View File

@ -5,11 +5,10 @@
#include <stdbool.h>
#include <string.h>
#include <unibilium.h>
#include "nvim/log.h"
#include "nvim/globals.h"
#include "nvim/log.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/option.h"
@ -29,12 +28,12 @@ bool terminfo_is_term_family(const char *term, const char *family)
size_t tlen = strlen(term);
size_t flen = strlen(family);
return tlen >= flen
&& 0 == memcmp(term, family, flen)
// Per commentary in terminfo, minus is the only valid suffix separator.
// The screen terminfo may have a terminal name like screen.xterm. By making
// the dot(.) a valid separator, such terminal names will also be the
// terminal family of the screen.
&& ('\0' == term[flen] || '-' == term[flen] || '.' == term[flen]);
&& 0 == memcmp(term, family, flen)
// Per commentary in terminfo, minus is the only valid suffix separator.
// The screen terminfo may have a terminal name like screen.xterm. By making
// the dot(.) a valid separator, such terminal names will also be the
// terminal family of the screen.
&& ('\0' == term[flen] || '-' == term[flen] || '.' == term[flen]);
}
bool terminfo_is_bsd_console(const char *term)