aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/ex_cmds.c36
-rw-r--r--src/nvim/ex_cmds2.c1
-rw-r--r--src/nvim/ex_docmd.c4
-rw-r--r--src/nvim/ex_getln.c2
-rw-r--r--src/nvim/fileio.c504
-rw-r--r--src/nvim/globals.h106
-rw-r--r--src/nvim/if_cscope.c5
-rw-r--r--src/nvim/memfile.c1
-rw-r--r--src/nvim/memline.c1
-rw-r--r--src/nvim/os/dl.c2
-rw-r--r--src/nvim/os/env.c4
-rw-r--r--src/nvim/os/time.c4
-rw-r--r--src/nvim/os/win_defs.h8
-rw-r--r--src/nvim/path.c2
-rw-r--r--src/nvim/shada.c1
-rw-r--r--src/nvim/undo.c1
16 files changed, 352 insertions, 330 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 34c25589d4..29d87d0fc1 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -951,30 +951,26 @@ void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, int do_out)
xfree(newcmd);
}
-/*
- * do_filter: filter lines through a command given by the user
- *
- * We mostly use temp files and the call_shell() routine here. This would
- * normally be done using pipes on a UNIX machine, but this is more portable
- * to non-unix machines. The call_shell() routine needs to be able
- * to deal with redirection somehow, and should handle things like looking
- * at the PATH env. variable, and adding reasonable extensions to the
- * command name given by the user. All reasonable versions of call_shell()
- * do this.
- * Alternatively, if on Unix and redirecting input or output, but not both,
- * and the 'shelltemp' option isn't set, use pipes.
- * We use input redirection if do_in is TRUE.
- * We use output redirection if do_out is TRUE.
- */
-static void
-do_filter (
+// do_filter: filter lines through a command given by the user
+//
+// We mostly use temp files and the call_shell() routine here. This would
+// normally be done using pipes on a Unix system, but this is more portable
+// to non-Unix systems. The call_shell() routine needs to be able
+// to deal with redirection somehow, and should handle things like looking
+// at the PATH env. variable, and adding reasonable extensions to the
+// command name given by the user. All reasonable versions of call_shell()
+// do this.
+// Alternatively, if on Unix and redirecting input or output, but not both,
+// and the 'shelltemp' option isn't set, use pipes.
+// We use input redirection if do_in is TRUE.
+// We use output redirection if do_out is TRUE.
+static void do_filter(
linenr_T line1,
linenr_T line2,
exarg_T *eap, /* for forced 'ff' and 'fenc' */
char_u *cmd,
int do_in,
- int do_out
-)
+ int do_out)
{
char_u *itmp = NULL;
char_u *otmp = NULL;
@@ -1690,7 +1686,7 @@ check_overwrite (
&& os_file_exists(ffname)) {
if (!eap->forceit && !eap->append) {
#ifdef UNIX
- /* with UNIX it is possible to open a directory */
+ // It is possible to open a directory on Unix.
if (os_isdir(ffname)) {
EMSG2(_(e_isadir2), ffname);
return FAIL;
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index 57153cf5a1..47774f5a99 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -6,6 +6,7 @@
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
+#include <fcntl.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 84bd31d9ad..cbe7c1a231 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -6843,9 +6843,9 @@ void ex_cd(exarg_T *eap)
prev_dir = NULL;
#if defined(UNIX)
- /* for UNIX ":cd" means: go to home directory */
+ // On Unix ":cd" means: go to home directory.
if (*new_dir == NUL) {
- /* use NameBuff for home directory name */
+ // Use NameBuff for home directory name.
expand_env((char_u *)"$HOME", NameBuff, MAXPATHL);
new_dir = NameBuff;
}
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 6d81f3680a..eca62da949 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -596,7 +596,7 @@ static int command_line_execute(VimState *state, int key)
}
if (s->j > 0) {
- // TODO(tarruda): this is only for DOS/UNIX systems - need to put in
+ // TODO(tarruda): this is only for DOS/Unix systems - need to put in
// machine-specific stuff here and in upseg init
cmdline_del(s->j);
put_on_cmdline(upseg + 1, 3, false);
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index bd0f0fc80a..26376afa27 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -7,6 +7,7 @@
#include <stdbool.h>
#include <string.h>
#include <inttypes.h>
+#include <fcntl.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
@@ -366,14 +367,13 @@ readfile (
/* don't display the file info for another buffer now */
need_fileinfo = FALSE;
- /*
- * For Unix: Use the short file name whenever possible.
- * Avoids problems with networks and when directory names are changed.
- * Don't do this for MS-DOS, a "cd" in a sub-shell may have moved us to
- * another directory, which we don't detect.
- */
- if (sfname == NULL)
+ // For Unix: Use the short file name whenever possible.
+ // Avoids problems with networks and when directory names are changed.
+ // Don't do this for Windows, a "cd" in a sub-shell may have moved us to
+ // another directory, which we don't detect.
+ if (sfname == NULL) {
sfname = fname;
+ }
#if defined(UNIX)
fname = sfname;
#endif
@@ -1992,13 +1992,14 @@ failed:
}
#ifdef OPEN_CHR_FILES
-/*
- * Returns TRUE if the file name argument is of the form "/dev/fd/\d\+",
- * which is the name of files used for process substitution output by
- * some shells on some operating systems, e.g., bash on SunOS.
- * Do not accept "/dev/fd/[012]", opening these may hang Vim.
- */
-static int is_dev_fd_file(char_u *fname)
+/// Returns true if the file name argument is of the form "/dev/fd/\d\+",
+/// which is the name of files used for process substitution output by
+/// some shells on some operating systems, e.g., bash on SunOS.
+/// Do not accept "/dev/fd/[012]", opening these may hang Vim.
+///
+/// @param fname file name to check
+static bool is_dev_fd_file(char_u *fname)
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
return STRNCMP(fname, "/dev/fd/", 8) == 0
&& ascii_isdigit(fname[8])
@@ -2353,13 +2354,12 @@ buf_write (
if (sfname == NULL)
sfname = fname;
- /*
- * For Unix: Use the short file name whenever possible.
- * Avoids problems with networks and when directory names are changed.
- * Don't do this for MS-DOS, a "cd" in a sub-shell may have moved us to
- * another directory, which we don't detect
- */
- ffname = fname; /* remember full fname */
+
+ // For Unix: Use the short file name whenever possible.
+ // Avoids problems with networks and when directory names are changed.
+ // Don't do this for Windows, a "cd" in a sub-shell may have moved us to
+ // another directory, which we don't detect.
+ ffname = fname; // remember full fname
#ifdef UNIX
fname = sfname;
#endif
@@ -3807,29 +3807,30 @@ void msg_add_fname(buf_T *buf, char_u *fname)
STRCAT(IObuff, "\" ");
}
-/*
- * Append message for text mode to IObuff.
- * Return TRUE if something appended.
- */
-static int msg_add_fileformat(int eol_type)
+/// Append message for text mode to IObuff.
+///
+/// @param eol_type line ending type
+///
+/// @return true if something was appended.
+static bool msg_add_fileformat(int eol_type)
{
#ifndef USE_CRNL
if (eol_type == EOL_DOS) {
STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[dos]") : _("[dos format]"));
- return TRUE;
+ return true;
}
#endif
if (eol_type == EOL_MAC) {
STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[mac]") : _("[mac format]"));
- return TRUE;
+ return true;
}
#ifdef USE_CRNL
if (eol_type == EOL_UNIX) {
STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[unix]") : _("[unix format]"));
- return TRUE;
+ return true;
}
#endif
- return FALSE;
+ return false;
}
/*
@@ -3893,7 +3894,11 @@ static int check_mtime(buf_T *buf, FileInfo *file_info)
return OK;
}
-static int time_differs(long t1, long t2)
+/// Return true if the times differ
+///
+/// @param t1 first time
+/// @param t2 second time
+static bool time_differs(long t1, long t2) FUNC_ATTR_CONST
{
#if defined(__linux__) || defined(MSWIN)
/* On a FAT filesystem, esp. under Linux, there are only 5 bits to store
@@ -4082,19 +4087,17 @@ static int buf_write_bytes(struct bw_info *ip)
return (wlen < len) ? FAIL : OK;
}
-/*
- * Convert a Unicode character to bytes.
- * Return TRUE for an error, FALSE when it's OK.
- */
-static int
-ucs2bytes (
- unsigned c, /* in: character */
- char_u **pp, /* in/out: pointer to result */
- int flags /* FIO_ flags */
-)
+/// Convert a Unicode character to bytes.
+///
+/// @param c character to convert
+/// @param[in,out] pp pointer to store the result at
+/// @param flags FIO_ flags that specify which encoding to use
+///
+/// @return true for an error, false when it's OK.
+static bool ucs2bytes(unsigned c, char_u **pp, int flags) FUNC_ATTR_NONNULL_ALL
{
char_u *p = *pp;
- int error = FALSE;
+ bool error = false;
int cc;
@@ -4116,8 +4119,9 @@ ucs2bytes (
/* Make two words, ten bits of the character in each. First
* word is 0xd800 - 0xdbff, second one 0xdc00 - 0xdfff */
c -= 0x10000;
- if (c >= 0x100000)
- error = TRUE;
+ if (c >= 0x100000) {
+ error = true;
+ }
cc = ((c >> 10) & 0x3ff) + 0xd800;
if (flags & FIO_ENDIAN_L) {
*p++ = cc;
@@ -4127,8 +4131,9 @@ ucs2bytes (
*p++ = cc;
}
c = (c & 0x3ff) + 0xdc00;
- } else
- error = TRUE;
+ } else {
+ error = true;
+ }
}
if (flags & FIO_ENDIAN_L) {
*p++ = c;
@@ -4139,7 +4144,7 @@ ucs2bytes (
}
} else { /* Latin1 */
if (c >= 0x100) {
- error = TRUE;
+ error = true;
*p++ = 0xBF;
} else
*p++ = c;
@@ -4149,11 +4154,14 @@ ucs2bytes (
return error;
}
-/*
- * Return TRUE if file encoding "fenc" requires conversion from or to
- * 'encoding'.
- */
-static int need_conversion(char_u *fenc)
+/// Return true if file encoding "fenc" requires conversion from or to
+/// 'encoding'.
+///
+/// @param fenc file encoding to check
+///
+/// @return true if conversion is required
+static bool need_conversion(const char_u *fenc)
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
int same_encoding;
int enc_flags;
@@ -4180,19 +4188,19 @@ static int need_conversion(char_u *fenc)
return !(enc_utf8 && fenc_flags == FIO_UTF8);
}
-/*
- * Check "ptr" for a unicode encoding and return the FIO_ flags needed for the
- * internal conversion.
- * if "ptr" is an empty string, use 'encoding'.
- */
-static int get_fio_flags(char_u *ptr)
+/// Return the FIO_ flags needed for the internal conversion if 'name' was
+/// unicode or latin1, otherwise 0. If "name" is an empty string,
+/// use 'encoding'.
+///
+/// @param name string to check for encoding
+static int get_fio_flags(const char_u *name)
{
int prop;
- if (*ptr == NUL)
- ptr = p_enc;
-
- prop = enc_canon_props(ptr);
+ if (*name == NUL) {
+ name = p_enc;
+ }
+ prop = enc_canon_props(name);
if (prop & ENC_UNICODE) {
if (prop & ENC_2BYTE) {
if (prop & ENC_ENDIAN_L)
@@ -4424,11 +4432,15 @@ char *modname(const char *fname, const char *ext, bool prepend_dot)
return retval;
}
-/*
- * Like fgets(), but if the file line is too long, it is truncated and the
- * rest of the line is thrown away. Returns TRUE for end-of-file.
- */
-int vim_fgets(char_u *buf, int size, FILE *fp)
+/// Like fgets(), but if the file line is too long, it is truncated and the
+/// rest of the line is thrown away.
+///
+/// @param[out] buf buffer to fill
+/// @param size size of the buffer
+/// @param fp file to read from
+///
+/// @return true for end-of-file.
+bool vim_fgets(char_u *buf, int size, FILE *fp) FUNC_ATTR_NONNULL_ALL
{
char *eof;
#define FGETS_SIZE 200
@@ -5327,11 +5339,13 @@ static void au_del_group(char_u *name)
}
}
-/*
- * Find the ID of an autocmd group name.
- * Return it's ID. Returns AUGROUP_ERROR (< 0) for error.
- */
-static int au_find_group(char_u *name)
+/// Find the ID of an autocmd group name.
+///
+/// @param name augroup name
+///
+/// @return the ID or AUGROUP_ERROR (< 0) for error.
+static int au_find_group(const char_u *name)
+ FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
for (int i = 0; i < augroups.ga_len; ++i) {
if (AUGROUP_NAME(i) != NULL && STRCMP(AUGROUP_NAME(i), name) == 0) {
@@ -5341,10 +5355,11 @@ static int au_find_group(char_u *name)
return AUGROUP_ERROR;
}
-/*
- * Return TRUE if augroup "name" exists.
- */
-int au_has_group(char_u *name)
+/// Return true if augroup "name" exists.
+///
+/// @param name augroup name
+bool au_has_group(const char_u *name)
+ FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
return au_find_group(name) != AUGROUP_ERROR;
}
@@ -5461,21 +5476,24 @@ find_end_event (
return pat;
}
-/*
- * Return TRUE if "event" is included in 'eventignore'.
- */
-static int event_ignored(event_T event)
+/// Return true if "event" is included in 'eventignore'.
+///
+/// @param event event to check
+static bool event_ignored(event_T event)
+ FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
- char_u *p = p_ei;
+ char_u *p = p_ei;
while (*p != NUL) {
- if (STRNICMP(p, "all", 3) == 0 && (p[3] == NUL || p[3] == ','))
- return TRUE;
- if (event_name2nr(p, &p) == event)
- return TRUE;
+ if (STRNICMP(p, "all", 3) == 0 && (p[3] == NUL || p[3] == ',')) {
+ return true;
+ }
+ if (event_name2nr(p, &p) == event) {
+ return true;
+ }
}
- return FALSE;
+ return false;
}
/*
@@ -5992,18 +6010,19 @@ void ex_doautoall(exarg_T *eap)
check_cursor(); /* just in case lines got deleted */
}
-/*
- * Check *argp for <nomodeline>. When it is present return FALSE, otherwise
- * return TRUE and advance *argp to after it.
- * Thus return TRUE when do_modelines() should be called.
- */
-int check_nomodeline(char_u **argp)
+/// Check *argp for <nomodeline>. When it is present return false, otherwise
+/// return true and advance *argp to after it. Thus do_modelines() should be
+/// called when true is returned.
+///
+/// @param[in,out] argp argument string
+bool check_nomodeline(char_u **argp)
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
if (STRNCMP(*argp, "<nomodeline>", 12) == 0) {
*argp = skipwhite(*argp + 12);
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
/*
@@ -6180,76 +6199,78 @@ win_found:
static int autocmd_nested = FALSE;
-/*
- * Execute autocommands for "event" and file name "fname".
- * Return TRUE if some commands were executed.
- */
-int
-apply_autocmds (
- event_T event,
- char_u *fname, /* NULL or empty means use actual file name */
- char_u *fname_io, /* fname to use for <afile> on cmdline */
- int force, /* when TRUE, ignore autocmd_busy */
- buf_T *buf /* buffer for <abuf> */
-)
+/// Execute autocommands for "event" and file name "fname".
+///
+/// @param event event that occured
+/// @param fname filename, NULL or empty means use actual file name
+/// @param fname_io filename to use for <afile> on cmdline
+/// @param force When true, ignore autocmd_busy
+/// @param buf Buffer for <abuf>
+///
+/// @return true if some commands were executed.
+bool apply_autocmds(event_T event, char_u *fname, char_u *fname_io, bool force,
+ buf_T *buf)
{
return apply_autocmds_group(event, fname, fname_io, force,
AUGROUP_ALL, buf, NULL);
}
-/*
- * Like apply_autocmds(), but with extra "eap" argument. This takes care of
- * setting v:filearg.
- */
-static int apply_autocmds_exarg(event_T event, char_u *fname, char_u *fname_io, int force, buf_T *buf, exarg_T *eap)
+/// Like apply_autocmds(), but with extra "eap" argument. This takes care of
+/// setting v:filearg.
+///
+/// @param event event that occured
+/// @param fname NULL or empty means use actual file name
+/// @param fname_io fname to use for <afile> on cmdline
+/// @param force When true, ignore autocmd_busy
+/// @param buf Buffer for <abuf>
+/// @param exarg Ex command arguments
+///
+/// @return true if some commands were executed.
+static bool apply_autocmds_exarg(event_T event, char_u *fname, char_u *fname_io,
+ bool force, buf_T *buf, exarg_T *eap)
{
return apply_autocmds_group(event, fname, fname_io, force,
AUGROUP_ALL, buf, eap);
}
-/*
- * Like apply_autocmds(), but handles the caller's retval. If the script
- * processing is being aborted or if retval is FAIL when inside a try
- * conditional, no autocommands are executed. If otherwise the autocommands
- * cause the script to be aborted, retval is set to FAIL.
- */
-int
-apply_autocmds_retval (
- event_T event,
- char_u *fname, /* NULL or empty means use actual file name */
- char_u *fname_io, /* fname to use for <afile> on cmdline */
- int force, /* when TRUE, ignore autocmd_busy */
- buf_T *buf, /* buffer for <abuf> */
- int *retval /* pointer to caller's retval */
-)
+/// Like apply_autocmds(), but handles the caller's retval. If the script
+/// processing is being aborted or if retval is FAIL when inside a try
+/// conditional, no autocommands are executed. If otherwise the autocommands
+/// cause the script to be aborted, retval is set to FAIL.
+///
+/// @param event event that occured
+/// @param fname NULL or empty means use actual file name
+/// @param fname_io fname to use for <afile> on cmdline
+/// @param force When true, ignore autocmd_busy
+/// @param buf Buffer for <abuf>
+/// @param[in,out] retval caller's retval
+///
+/// @return true if some autocommands were executed
+bool apply_autocmds_retval(event_T event, char_u *fname, char_u *fname_io,
+ bool force, buf_T *buf, int *retval)
{
- int did_cmd;
-
- if (should_abort(*retval))
- return FALSE;
+ if (should_abort(*retval)) {
+ return false;
+ }
- did_cmd = apply_autocmds_group(event, fname, fname_io, force,
- AUGROUP_ALL, buf, NULL);
- if (did_cmd
- && aborting()
- )
+ bool did_cmd = apply_autocmds_group(event, fname, fname_io, force,
+ AUGROUP_ALL, buf, NULL);
+ if (did_cmd && aborting()) {
*retval = FAIL;
+ }
return did_cmd;
}
-/*
- * Return TRUE when there is a CursorHold autocommand defined.
- */
-int has_cursorhold(void)
+/// Return true when there is a CursorHold/CursorHoldI autocommand defined for
+/// the current mode.
+bool has_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
return first_autopat[(int)(get_real_state() == NORMAL_BUSY
? EVENT_CURSORHOLD : EVENT_CURSORHOLDI)] != NULL;
}
-/*
- * Return TRUE if the CursorHold event can be triggered.
- */
-int trigger_cursorhold(void)
+/// Return true if the CursorHold/CursorHoldI event can be triggered.
+bool trigger_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
int state;
@@ -6260,10 +6281,11 @@ int trigger_cursorhold(void)
&& !ins_compl_active()
) {
state = get_real_state();
- if (state == NORMAL_BUSY || (state & INSERT) != 0)
- return TRUE;
+ if (state == NORMAL_BUSY || (state & INSERT) != 0) {
+ return true;
+ }
}
- return FALSE;
+ return false;
}
/// Return true if "event" autocommand is defined.
@@ -6274,23 +6296,27 @@ bool has_event(int event) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
return first_autopat[event] != NULL;
}
-static int
-apply_autocmds_group (
- event_T event,
- char_u *fname, /* NULL or empty means use actual file name */
- char_u *fname_io, /* fname to use for <afile> on cmdline, NULL means
- use fname */
- int force, /* when TRUE, ignore autocmd_busy */
- int group, /* group ID, or AUGROUP_ALL */
- buf_T *buf, /* buffer for <abuf> */
- exarg_T *eap /* command arguments */
-)
+/// Execute autocommands for "event" and file name "fname".
+///
+/// @param event event that occured
+/// @param fname filename, NULL or empty means use actual file name
+/// @param fname_io filename to use for <afile> on cmdline,
+/// NULL means use `fname`.
+/// @param force When true, ignore autocmd_busy
+/// @param group autocmd group ID or AUGROUP_ALL
+/// @param buf Buffer for <abuf>
+/// @param exarg Ex command arguments
+///
+/// @return true if some commands were executed.
+static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io,
+ bool force, int group, buf_T *buf,
+ exarg_T *eap)
{
char_u *sfname = NULL; /* short file name */
char_u *tail;
bool save_changed;
buf_T *old_curbuf;
- int retval = FALSE;
+ bool retval = false;
char_u *save_sourcing_name;
linenr_T save_sourcing_lnum;
char_u *save_autocmd_fname;
@@ -6444,17 +6470,16 @@ apply_autocmds_group (
}
if (fname == NULL) { /* out of memory */
xfree(sfname);
- retval = FALSE;
+ retval = false;
goto BYPASS_AU;
}
#ifdef BACKSLASH_IN_FILENAME
- /*
- * Replace all backslashes with forward slashes. This makes the
- * autocommand patterns portable between Unix and MS-DOS.
- */
- if (sfname != NULL)
+ // Replace all backslashes with forward slashes. This makes the
+ // autocommand patterns portable between Unix and Windows.
+ if (sfname != NULL) {
forward_slash(sfname);
+ }
forward_slash(fname);
#endif
@@ -6528,17 +6553,19 @@ apply_autocmds_group (
if (eap != NULL) {
save_cmdarg = set_cmdarg(eap, NULL);
set_vim_var_nr(VV_CMDBANG, (long)eap->forceit);
- } else
- save_cmdarg = NULL; /* avoid gcc warning */
- retval = TRUE;
- /* mark the last pattern, to avoid an endless loop when more patterns
- * are added when executing autocommands */
- for (ap = patcmd.curpat; ap->next != NULL; ap = ap->next)
- ap->last = FALSE;
- ap->last = TRUE;
- check_lnums(TRUE); /* make sure cursor and topline are valid */
+ } else {
+ save_cmdarg = NULL; // avoid gcc warning
+ }
+ retval = true;
+ // mark the last pattern, to avoid an endless loop when more patterns
+ // are added when executing autocommands
+ for (ap = patcmd.curpat; ap->next != NULL; ap = ap->next) {
+ ap->last = false;
+ }
+ ap->last = true;
+ check_lnums(true); // make sure cursor and topline are valid
do_cmdline(NULL, getnextac, (void *)&patcmd,
- DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
+ DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
if (eap != NULL) {
(void)set_cmdarg(NULL, save_cmdarg);
set_vim_var_nr(VV_CMDBANG, save_cmdbang);
@@ -6754,42 +6781,44 @@ char_u *getnextac(int c, void *cookie, int indent)
return retval;
}
-/*
- * Return TRUE if there is a matching autocommand for "fname".
- * To account for buffer-local autocommands, function needs to know
- * in which buffer the file will be opened.
- */
-int has_autocmd(event_T event, char_u *sfname, buf_T *buf)
+/// Return true if there is a matching autocommand for "fname".
+/// To account for buffer-local autocommands, function needs to know
+/// in which buffer the file will be opened.
+///
+/// @param event event that occured.
+/// @param sfname filename the event occured in.
+/// @param buf buffer the file is open in
+bool has_autocmd(event_T event, char_u *sfname, buf_T *buf)
+ FUNC_ATTR_WARN_UNUSED_RESULT
{
AutoPat *ap;
char_u *fname;
char_u *tail = path_tail(sfname);
- int retval = FALSE;
+ bool retval = false;
- fname = (char_u *)FullName_save((char *)sfname, FALSE);
- if (fname == NULL)
- return FALSE;
+ fname = (char_u *)FullName_save((char *)sfname, false);
+ if (fname == NULL) {
+ return false;
+ }
#ifdef BACKSLASH_IN_FILENAME
- /*
- * Replace all backslashes with forward slashes. This makes the
- * autocommand patterns portable between Unix and MS-DOS.
- */
+ // Replace all backslashes with forward slashes. This makes the
+ // autocommand patterns portable between Unix and Windows.
sfname = vim_strsave(sfname);
forward_slash(sfname);
forward_slash(fname);
#endif
- for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
+ for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) {
if (ap->pat != NULL && ap->cmds != NULL
&& (ap->buflocal_nr == 0
? match_file_pat(NULL, &ap->reg_prog, fname, sfname, tail,
ap->allow_dirs)
- : buf != NULL && ap->buflocal_nr == buf->b_fnum
- )) {
- retval = TRUE;
+ : buf != NULL && ap->buflocal_nr == buf->b_fnum)) {
+ retval = true;
break;
}
+ }
xfree(fname);
#ifdef BACKSLASH_IN_FILENAME
@@ -6877,29 +6906,27 @@ char_u *get_event_name(expand_T *xp, int idx)
}
-/*
- * Return TRUE if autocmd is supported.
- */
-int autocmd_supported(char_u *name)
+/// Return true if autocmd "event" is supported.
+bool autocmd_supported(char_u *event)
{
char_u *p;
- return event_name2nr(name, &p) != NUM_EVENTS;
+ return event_name2nr(event, &p) != NUM_EVENTS;
}
-/*
- * Return TRUE if an autocommand is defined for a group, event and
- * pattern: The group can be omitted to accept any group. "event" and "pattern"
- * can be NULL to accept any event and pattern. "pattern" can be NULL to accept
- * any pattern. Buffer-local patterns <buffer> or <buffer=N> are accepted.
- * Used for:
- * exists("#Group") or
- * exists("#Group#Event") or
- * exists("#Group#Event#pat") or
- * exists("#Event") or
- * exists("#Event#pat")
- */
-int au_exists(char_u *arg)
+/// Return true if an autocommand is defined for a group, event and
+/// pattern: The group can be omitted to accept any group.
+/// `event` and `pattern` can be omitted to accept any event and pattern.
+/// Buffer-local patterns <buffer> or <buffer=N> are accepted.
+/// Used for:
+/// exists("#Group") or
+/// exists("#Group#Event") or
+/// exists("#Group#Event#pat") or
+/// exists("#Event") or
+/// exists("#Event#pat")
+///
+/// @param arg autocommand string
+bool au_exists(const char_u *arg) FUNC_ATTR_WARN_UNUSED_RESULT
{
char_u *arg_save;
char_u *pattern = NULL;
@@ -6909,7 +6936,7 @@ int au_exists(char_u *arg)
AutoPat *ap;
buf_T *buflocal_buf = NULL;
int group;
- int retval = FALSE;
+ bool retval = false;
/* Make a copy so that we can change the '#' chars to a NUL. */
arg_save = vim_strsave(arg);
@@ -6925,8 +6952,8 @@ int au_exists(char_u *arg)
event_name = arg_save;
} else {
if (p == NULL) {
- /* "Group": group name is present and it's recognized */
- retval = TRUE;
+ // "Group": group name is present and it's recognized
+ retval = true;
goto theend;
}
@@ -6968,7 +6995,7 @@ int au_exists(char_u *arg)
|| (buflocal_buf == NULL
? fnamecmp(ap->pat, pattern) == 0
: ap->buflocal_nr == buflocal_buf->b_fnum))) {
- retval = TRUE;
+ retval = true;
break;
}
@@ -6983,12 +7010,13 @@ theend:
///
/// Used for autocommands and 'wildignore'.
///
-/// @param pattern the pattern to match with
-/// @param prog the pre-compiled regprog or NULL
-/// @param fname the full path of the file name
-/// @param sfname the short file name or NULL
-/// @param tail the tail of the path
-/// @param allow_dirs allow matching with dir
+/// @param pattern pattern to match with
+/// @param prog pre-compiled regprog or NULL
+/// @param fname full path of the file name
+/// @param sfname short file name or NULL
+/// @param tail tail of the path
+/// @param allow_dirs Allow matching with dir
+///
/// @return true if there is a match, false otherwise
static bool match_file_pat(char_u *pattern, regprog_T **prog, char_u *fname,
char_u *sfname, char_u *tail, int allow_dirs)
@@ -7027,12 +7055,17 @@ static bool match_file_pat(char_u *pattern, regprog_T **prog, char_u *fname,
return result;
}
-/*
- * Return TRUE if a file matches with a pattern in "list".
- * "list" is a comma-separated list of patterns, like 'wildignore'.
- * "sfname" is the short file name or NULL, "ffname" the long file name.
- */
-int match_file_list(char_u *list, char_u *sfname, char_u *ffname)
+/// Check if a file matches with a pattern in "list".
+/// "list" is a comma-separated list of patterns, like 'wildignore'.
+/// "sfname" is the short file name or NULL, "ffname" the long file name.
+///
+/// @param list list of patterns to match
+/// @param sfname short file name
+/// @param ffname full file name
+///
+/// @return true if there was a match
+bool match_file_list(char_u *list, char_u *sfname, char_u *ffname)
+ FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1, 3)
{
char_u buf[100];
char_u *tail;
@@ -7043,20 +7076,21 @@ int match_file_list(char_u *list, char_u *sfname, char_u *ffname)
tail = path_tail(sfname);
- /* try all patterns in 'wildignore' */
+ // try all patterns in 'wildignore'
p = list;
while (*p) {
- copy_option_part(&p, buf, 100, ",");
- regpat = file_pat_to_reg_pat(buf, NULL, &allow_dirs, FALSE);
- if (regpat == NULL)
+ copy_option_part(&p, buf, ARRAY_SIZE(buf), ",");
+ regpat = file_pat_to_reg_pat(buf, NULL, &allow_dirs, false);
+ if (regpat == NULL) {
break;
- match = match_file_pat(regpat, NULL, ffname, sfname,
- tail, (int)allow_dirs);
+ }
+ match = match_file_pat(regpat, NULL, ffname, sfname, tail, (int)allow_dirs);
xfree(regpat);
- if (match)
- return TRUE;
+ if (match) {
+ return true;
+ }
}
- return FALSE;
+ return false;
}
/// Convert the given pattern "pat" which has shell style wildcards in it, into
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 50eda6cb17..b45f13de4c 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -8,11 +8,10 @@
// actually defined and initialized.
#ifndef EXTERN
# define EXTERN extern
-# define INIT(x)
+# define INIT(...)
#else
# ifndef INIT
-# define INIT(x) x
-# define DO_INIT
+# define INIT(...) __VA_ARGS__
# endif
#endif
@@ -117,12 +116,9 @@
#define DFLT_COLS 80 /* default value for 'columns' */
#define DFLT_ROWS 24 /* default value for 'lines' */
-EXTERN long Rows /* nr of rows in the screen */
-#ifdef DO_INIT
- = DFLT_ROWS
-#endif
-;
-EXTERN long Columns INIT(= DFLT_COLS); /* nr of columns in the screen */
+EXTERN long Rows INIT(= DFLT_ROWS); // nr of rows in the screen
+
+EXTERN long Columns INIT(= DFLT_COLS); // nr of columns in the screen
/*
* The characters and attributes cached for the screen.
@@ -751,11 +747,8 @@ EXTERN int can_si INIT(= FALSE);
*/
EXTERN int can_si_back INIT(= FALSE);
-EXTERN pos_T saved_cursor /* w_cursor before formatting text. */
-#ifdef DO_INIT
- = INIT_POS_T(0, 0, 0)
-#endif
-;
+// w_cursor before formatting text.
+EXTERN pos_T saved_cursor INIT(= INIT_POS_T(0, 0, 0));
/*
* Stuff for insert mode.
@@ -917,19 +910,16 @@ EXTERN int RedrawingDisabled INIT(= 0);
EXTERN int readonlymode INIT(= FALSE); /* Set to TRUE for "view" */
EXTERN int recoverymode INIT(= FALSE); /* Set to TRUE for "-r" option */
-EXTERN typebuf_T typebuf /* typeahead buffer */
-#ifdef DO_INIT
- = {NULL, NULL, 0, 0, 0, 0, 0, 0, 0}
-#endif
-;
-EXTERN int ex_normal_busy INIT(= 0); /* recursiveness of ex_normal() */
-EXTERN int ex_normal_lock INIT(= 0); /* forbid use of ex_normal() */
-EXTERN int ignore_script INIT(= FALSE); /* ignore script input */
-EXTERN int stop_insert_mode; /* for ":stopinsert" and 'insertmode' */
+// typeahead buffer
+EXTERN typebuf_T typebuf INIT(= { NULL, NULL, 0, 0, 0, 0, 0, 0, 0 });
-EXTERN int KeyTyped; /* TRUE if user typed current char */
-EXTERN int KeyStuffed; /* TRUE if current char from stuffbuf */
-EXTERN int maptick INIT(= 0); /* tick for each non-mapped char */
+EXTERN int ex_normal_busy INIT(= 0); // recursiveness of ex_normal()
+EXTERN int ex_normal_lock INIT(= 0); // forbid use of ex_normal()
+EXTERN int ignore_script INIT(= false); // ignore script input
+EXTERN int stop_insert_mode; // for ":stopinsert" and 'insertmode'
+EXTERN int KeyTyped; // TRUE if user typed current char
+EXTERN int KeyStuffed; // TRUE if current char from stuffbuf
+EXTERN int maptick INIT(= 0); // tick for each non-mapped char
EXTERN char_u chartab[256]; /* table used in charset.c; See
init_chartab() for explanation */
@@ -959,30 +949,28 @@ EXTERN reg_extmatch_T *re_extmatch_in INIT(= NULL); /* Used by vim_regexec():
EXTERN reg_extmatch_T *re_extmatch_out INIT(= NULL); /* Set by vim_regexec()
* to store \z\(...\) matches */
-EXTERN int did_outofmem_msg INIT(= FALSE);
-/* set after out of memory msg */
-EXTERN int did_swapwrite_msg INIT(= FALSE);
-/* set after swap write error msg */
-EXTERN int undo_off INIT(= FALSE); /* undo switched off for now */
-EXTERN int global_busy INIT(= 0); /* set when :global is executing */
-EXTERN int listcmd_busy INIT(= FALSE); /* set when :argdo, :windo or
- :bufdo is executing */
-EXTERN int need_start_insertmode INIT(= FALSE);
-/* start insert mode soon */
-EXTERN char_u *last_cmdline INIT(= NULL); /* last command line (for ":) */
-EXTERN char_u *repeat_cmdline INIT(= NULL); /* command line for "." */
-EXTERN char_u *new_last_cmdline INIT(= NULL); /* new value for last_cmdline */
-EXTERN char_u *autocmd_fname INIT(= NULL); /* fname for <afile> on cmdline */
-EXTERN int autocmd_fname_full; /* autocmd_fname is full path */
-EXTERN int autocmd_bufnr INIT(= 0); /* fnum for <abuf> on cmdline */
-EXTERN char_u *autocmd_match INIT(= NULL); /* name for <amatch> on cmdline */
-EXTERN int did_cursorhold INIT(= FALSE); /* set when CursorHold t'gerd */
-EXTERN pos_T last_cursormoved /* for CursorMoved event */
-# ifdef DO_INIT
- = INIT_POS_T(0, 0, 0)
-# endif
-;
-EXTERN int last_changedtick INIT(= 0); /* for TextChanged event */
+EXTERN int did_outofmem_msg INIT(= false);
+// set after out of memory msg
+EXTERN int did_swapwrite_msg INIT(= false);
+// set after swap write error msg
+EXTERN int undo_off INIT(= false); // undo switched off for now
+EXTERN int global_busy INIT(= 0); // set when :global is executing
+EXTERN int listcmd_busy INIT(= false); // set when :argdo, :windo or
+ // :bufdo is executing
+EXTERN int need_start_insertmode INIT(= false);
+// start insert mode soon
+EXTERN char_u *last_cmdline INIT(= NULL); // last command line (for ":)
+EXTERN char_u *repeat_cmdline INIT(= NULL); // command line for "."
+EXTERN char_u *new_last_cmdline INIT(= NULL); // new value for last_cmdline
+EXTERN char_u *autocmd_fname INIT(= NULL); // fname for <afile> on cmdline
+EXTERN int autocmd_fname_full; // autocmd_fname is full path
+EXTERN int autocmd_bufnr INIT(= 0); // fnum for <abuf> on cmdline
+EXTERN char_u *autocmd_match INIT(= NULL); // name for <amatch> on cmdline
+EXTERN int did_cursorhold INIT(= false); // set when CursorHold t'gerd
+// for CursorMoved event
+EXTERN pos_T last_cursormoved INIT(= INIT_POS_T(0, 0, 0));
+
+EXTERN int last_changedtick INIT(= 0); // for TextChanged event
EXTERN buf_T *last_changedtick_buf INIT(= NULL);
EXTERN int postponed_split INIT(= 0); /* for CTRL-W CTRL-] command */
@@ -1092,13 +1080,9 @@ EXTERN int typebuf_was_filled INIT(= FALSE); /* received text from client
#ifdef BACKSLASH_IN_FILENAME
-EXTERN char psepc INIT(= '\\'); /* normal path separator character */
-EXTERN char psepcN INIT(= '/'); /* abnormal path separator character */
-EXTERN char pseps[2] /* normal path separator string */
-# ifdef DO_INIT
- = {'\\', 0}
-# endif
-;
+EXTERN char psepc INIT(= '\\'); // normal path separator character
+EXTERN char psepcN INIT(= '/'); // abnormal path separator character
+EXTERN char pseps[2] INIT(= { '\\', 0 }); // normal path separator string
#endif
/* Set to TRUE when an operator is being executed with virtual editing, MAYBE
@@ -1117,12 +1101,8 @@ EXTERN int need_cursor_line_redraw INIT(= FALSE);
#ifdef USE_MCH_ERRMSG
-/* Grow array to collect error messages in until they can be displayed. */
-EXTERN garray_T error_ga
-# ifdef DO_INIT
- = GA_EMPTY_INIT_VALUE
-# endif
-;
+// Grow array to collect error messages in until they can be displayed.
+EXTERN garray_T error_ga INIT(= GA_EMPTY_INIT_VALUE);
#endif
diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c
index cd206e2e0d..d236501b3f 100644
--- a/src/nvim/if_cscope.c
+++ b/src/nvim/if_cscope.c
@@ -11,6 +11,7 @@
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
+#include <fcntl.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
@@ -1841,9 +1842,7 @@ static void sig_handler(int s) {
*/
static void cs_release_csp(size_t i, int freefnpp)
{
- /*
- * Trying to exit normally (not sure whether it is fit to UNIX cscope
- */
+ // Trying to exit normally (not sure whether it is fit to Unix cscope)
if (csinfo[i].to_fp != NULL) {
(void)fputs("q\n", csinfo[i].to_fp);
(void)fflush(csinfo[i].to_fp);
diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c
index 137c7c49d3..8cf5642a80 100644
--- a/src/nvim/memfile.c
+++ b/src/nvim/memfile.c
@@ -40,6 +40,7 @@
#include <limits.h>
#include <string.h>
#include <stdbool.h>
+#include <fcntl.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index c91a25df6e..f58b2ac38f 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -38,6 +38,7 @@
#include <inttypes.h>
#include <string.h>
#include <stdbool.h>
+#include <fcntl.h>
#include "nvim/ascii.h"
#include "nvim/vim.h"
diff --git a/src/nvim/os/dl.c b/src/nvim/os/dl.c
index b4a35e203e..fef02cc784 100644
--- a/src/nvim/os/dl.c
+++ b/src/nvim/os/dl.c
@@ -63,7 +63,7 @@ bool os_libcall(const char *libname,
// call the library and save the result
// TODO(aktau): catch signals and use jmp (if available) to handle
- // exceptions. jmp's on UNIX seem to interact trickily with signals as
+ // 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;
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index a791dca39c..c1804067e9 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -142,7 +142,7 @@ void os_get_hostname(char *hostname, size_t len)
/// - go to that directory
/// - do os_dirname() to get the real name of that directory.
/// This also works with mounts and links.
-/// Don't do this for MS-DOS, it will change the "current dir" for a drive.
+/// Don't do this for Windows, it will change the "current dir" for a drive.
static char_u *homedir = NULL;
void init_homedir(void)
@@ -290,7 +290,7 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one,
}
#if defined(UNIX)
- // Verify that we have found the end of a UNIX ${VAR} style variable
+ // Verify that we have found the end of a Unix ${VAR} style variable
if (src[1] == '{' && *tail != '}') {
var = NULL;
} else {
diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c
index ba1dcf631a..188f0802c9 100644
--- a/src/nvim/os/time.c
+++ b/src/nvim/os/time.c
@@ -93,7 +93,7 @@ struct tm *os_localtime_r(const time_t *restrict clock,
#endif
}
-/// Obtains the current UNIX timestamp and adjusts it to local time
+/// Obtains the current Unix timestamp and adjusts it to local time.
///
/// @param result Pointer to a 'struct tm' where the result should be placed
/// @return A pointer to a 'struct tm' in the current time zone (the 'result'
@@ -104,7 +104,7 @@ struct tm *os_get_localtime(struct tm *result) FUNC_ATTR_NONNULL_ALL
return os_localtime_r(&rawtime, result);
}
-/// Obtains the current UNIX timestamp
+/// Obtains the current Unix timestamp.
///
/// @return Seconds since epoch.
Timestamp os_time(void)
diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h
index 2ce74c9818..ba96347a12 100644
--- a/src/nvim/os/win_defs.h
+++ b/src/nvim/os/win_defs.h
@@ -5,6 +5,10 @@
#include <sys/stat.h>
#include <stdio.h>
+// Windows does not have S_IFLNK but libuv defines it
+// and sets the flag for us when calling uv_fs_stat.
+#include <uv.h>
+
#define NAME_MAX _MAX_PATH
#define TEMP_DIR_NAMES {"$TMP", "$TEMP", "$USERPROFILE", ""}
@@ -50,6 +54,10 @@ typedef SSIZE_T ssize_t;
# endif
#endif
+#ifndef O_NOFOLLOW
+# define O_NOFOLLOW 0
+#endif
+
#if !defined(S_ISDIR) && defined(S_IFDIR)
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 23b22b67f1..5ac3d07f67 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -196,7 +196,7 @@ char_u *get_past_head(char_u *path)
int vim_ispathsep(int c)
{
#ifdef UNIX
- return c == '/'; /* UNIX has ':' inside file names */
+ return c == '/'; // Unix has ':' inside file names
#else
# ifdef BACKSLASH_IN_FILENAME
return c == ':' || c == '/' || c == '\\';
diff --git a/src/nvim/shada.c b/src/nvim/shada.c
index 59ef2a0d28..dcdf2195f8 100644
--- a/src/nvim/shada.c
+++ b/src/nvim/shada.c
@@ -5,6 +5,7 @@
#include <stdint.h>
#include <inttypes.h>
#include <errno.h>
+#include <fcntl.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index 69ac18ad54..6b60f95f22 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -77,6 +77,7 @@
#include <limits.h>
#include <stdbool.h>
#include <string.h>
+#include <fcntl.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"