fileio: Change return types to bool

Co-authored-by: Wayne Rowcliffe (@war1025)
This commit is contained in:
Charles Joachim
2016-01-07 20:30:40 -05:00
parent 55a345c3e7
commit a29b08ca5a

View File

@@ -1992,13 +1992,14 @@ failed:
} }
#ifdef OPEN_CHR_FILES #ifdef OPEN_CHR_FILES
/* /// Returns true if the file name argument is of the form "/dev/fd/\d\+",
* 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
* which is the name of files used for process substitution output by /// some shells on some operating systems, e.g., bash on SunOS.
* some shells on some operating systems, e.g., bash on SunOS. /// Do not accept "/dev/fd/[012]", opening these may hang Vim.
* Do not accept "/dev/fd/[012]", opening these may hang Vim. ///
*/ /// @param fname file name to check
static int is_dev_fd_file(char_u *fname) 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 return STRNCMP(fname, "/dev/fd/", 8) == 0
&& ascii_isdigit(fname[8]) && ascii_isdigit(fname[8])
@@ -3806,29 +3807,30 @@ void msg_add_fname(buf_T *buf, char_u *fname)
STRCAT(IObuff, "\" "); STRCAT(IObuff, "\" ");
} }
/* /// Append message for text mode to IObuff.
* Append message for text mode to IObuff. ///
* Return TRUE if something appended. /// @param eol_type line ending type
*/ ///
static int msg_add_fileformat(int eol_type) /// @return true if something was appended.
static bool msg_add_fileformat(int eol_type)
{ {
#ifndef USE_CRNL #ifndef USE_CRNL
if (eol_type == EOL_DOS) { if (eol_type == EOL_DOS) {
STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[dos]") : _("[dos format]")); STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[dos]") : _("[dos format]"));
return TRUE; return true;
} }
#endif #endif
if (eol_type == EOL_MAC) { if (eol_type == EOL_MAC) {
STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[mac]") : _("[mac format]")); STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[mac]") : _("[mac format]"));
return TRUE; return true;
} }
#ifdef USE_CRNL #ifdef USE_CRNL
if (eol_type == EOL_UNIX) { if (eol_type == EOL_UNIX) {
STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[unix]") : _("[unix format]")); STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[unix]") : _("[unix format]"));
return TRUE; return true;
} }
#endif #endif
return FALSE; return false;
} }
/* /*
@@ -3892,7 +3894,11 @@ static int check_mtime(buf_T *buf, FileInfo *file_info)
return OK; 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) #if defined(__linux__) || defined(MSWIN)
/* On a FAT filesystem, esp. under Linux, there are only 5 bits to store /* On a FAT filesystem, esp. under Linux, there are only 5 bits to store
@@ -4081,19 +4087,17 @@ static int buf_write_bytes(struct bw_info *ip)
return (wlen < len) ? FAIL : OK; return (wlen < len) ? FAIL : OK;
} }
/* /// Convert a Unicode character to bytes.
* Convert a Unicode character to bytes. ///
* Return TRUE for an error, FALSE when it's OK. /// @param c character to convert
*/ /// @param[in,out] pp pointer to store the result at
static int /// @param flags FIO_ flags that specify which encoding to use
ucs2bytes ( ///
unsigned c, /* in: character */ /// @return true for an error, false when it's OK.
char_u **pp, /* in/out: pointer to result */ static bool ucs2bytes(unsigned c, char_u **pp, int flags) FUNC_ATTR_NONNULL_ALL
int flags /* FIO_ flags */
)
{ {
char_u *p = *pp; char_u *p = *pp;
int error = FALSE; bool error = false;
int cc; int cc;
@@ -4115,8 +4119,9 @@ ucs2bytes (
/* Make two words, ten bits of the character in each. First /* Make two words, ten bits of the character in each. First
* word is 0xd800 - 0xdbff, second one 0xdc00 - 0xdfff */ * word is 0xd800 - 0xdbff, second one 0xdc00 - 0xdfff */
c -= 0x10000; c -= 0x10000;
if (c >= 0x100000) if (c >= 0x100000) {
error = TRUE; error = true;
}
cc = ((c >> 10) & 0x3ff) + 0xd800; cc = ((c >> 10) & 0x3ff) + 0xd800;
if (flags & FIO_ENDIAN_L) { if (flags & FIO_ENDIAN_L) {
*p++ = cc; *p++ = cc;
@@ -4126,8 +4131,9 @@ ucs2bytes (
*p++ = cc; *p++ = cc;
} }
c = (c & 0x3ff) + 0xdc00; c = (c & 0x3ff) + 0xdc00;
} else } else {
error = TRUE; error = true;
}
} }
if (flags & FIO_ENDIAN_L) { if (flags & FIO_ENDIAN_L) {
*p++ = c; *p++ = c;
@@ -4138,7 +4144,7 @@ ucs2bytes (
} }
} else { /* Latin1 */ } else { /* Latin1 */
if (c >= 0x100) { if (c >= 0x100) {
error = TRUE; error = true;
*p++ = 0xBF; *p++ = 0xBF;
} else } else
*p++ = c; *p++ = c;
@@ -4148,11 +4154,14 @@ ucs2bytes (
return error; return error;
} }
/* /// Return true if file encoding "fenc" requires conversion from or to
* Return TRUE if file encoding "fenc" requires conversion from or to /// 'encoding'.
* 'encoding'. ///
*/ /// @param fenc file encoding to check
static int need_conversion(char_u *fenc) ///
/// @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 same_encoding;
int enc_flags; int enc_flags;
@@ -4179,19 +4188,19 @@ static int need_conversion(char_u *fenc)
return !(enc_utf8 && fenc_flags == FIO_UTF8); return !(enc_utf8 && fenc_flags == FIO_UTF8);
} }
/* /// Return the FIO_ flags needed for the internal conversion if 'name' was
* Check "ptr" for a unicode encoding and return the FIO_ flags needed for the /// unicode or latin1, otherwise 0. If "name" is an empty string,
* internal conversion. /// use 'encoding'.
* if "ptr" is an empty string, use 'encoding'. ///
*/ /// @param name string to check for encoding
static int get_fio_flags(char_u *ptr) static int get_fio_flags(const char_u *name)
{ {
int prop; int prop;
if (*ptr == NUL) if (*name == NUL) {
ptr = p_enc; name = p_enc;
}
prop = enc_canon_props(ptr); prop = enc_canon_props(name);
if (prop & ENC_UNICODE) { if (prop & ENC_UNICODE) {
if (prop & ENC_2BYTE) { if (prop & ENC_2BYTE) {
if (prop & ENC_ENDIAN_L) if (prop & ENC_ENDIAN_L)
@@ -4423,11 +4432,15 @@ char *modname(const char *fname, const char *ext, bool prepend_dot)
return retval; return retval;
} }
/* /// Like fgets(), but if the file line is too long, it is truncated and the
* Like fgets(), but if the file line is too long, it is truncated and the /// rest of the line is thrown away.
* rest of the line is thrown away. Returns TRUE for end-of-file. ///
*/ /// @param[out] buf buffer to fill
int vim_fgets(char_u *buf, int size, FILE *fp) /// @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; char *eof;
#define FGETS_SIZE 200 #define FGETS_SIZE 200
@@ -5326,11 +5339,13 @@ static void au_del_group(char_u *name)
} }
} }
/* /// Find the ID of an autocmd group name.
* Find the ID of an autocmd group name. ///
* Return it's ID. Returns AUGROUP_ERROR (< 0) for error. /// @param name augroup name
*/ ///
static int au_find_group(char_u *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) { for (int i = 0; i < augroups.ga_len; ++i) {
if (AUGROUP_NAME(i) != NULL && STRCMP(AUGROUP_NAME(i), name) == 0) { if (AUGROUP_NAME(i) != NULL && STRCMP(AUGROUP_NAME(i), name) == 0) {
@@ -5340,10 +5355,11 @@ static int au_find_group(char_u *name)
return AUGROUP_ERROR; return AUGROUP_ERROR;
} }
/* /// Return true if augroup "name" exists.
* Return TRUE if augroup "name" exists. ///
*/ /// @param name augroup name
int au_has_group(char_u *name) bool au_has_group(const char_u *name)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
return au_find_group(name) != AUGROUP_ERROR; return au_find_group(name) != AUGROUP_ERROR;
} }
@@ -5460,21 +5476,24 @@ find_end_event (
return pat; return pat;
} }
/* /// Return true if "event" is included in 'eventignore'.
* Return TRUE if "event" is included in 'eventignore'. ///
*/ /// @param event event to check
static int event_ignored(event_T event) 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) { while (*p != NUL) {
if (STRNICMP(p, "all", 3) == 0 && (p[3] == NUL || p[3] == ',')) if (STRNICMP(p, "all", 3) == 0 && (p[3] == NUL || p[3] == ',')) {
return TRUE; return true;
if (event_name2nr(p, &p) == event) }
return TRUE; if (event_name2nr(p, &p) == event) {
return true;
}
} }
return FALSE; return false;
} }
/* /*
@@ -5991,18 +6010,19 @@ void ex_doautoall(exarg_T *eap)
check_cursor(); /* just in case lines got deleted */ check_cursor(); /* just in case lines got deleted */
} }
/* /// Check *argp for <nomodeline>. When it is present return false, otherwise
* Check *argp for <nomodeline>. When it is present return FALSE, otherwise /// return true and advance *argp to after it. Thus do_modelines() should be
* return TRUE and advance *argp to after it. /// called when true is returned.
* Thus return TRUE when do_modelines() should be called. ///
*/ /// @param[in,out] argp argument string
int check_nomodeline(char_u **argp) bool check_nomodeline(char_u **argp)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{ {
if (STRNCMP(*argp, "<nomodeline>", 12) == 0) { if (STRNCMP(*argp, "<nomodeline>", 12) == 0) {
*argp = skipwhite(*argp + 12); *argp = skipwhite(*argp + 12);
return FALSE; return false;
} }
return TRUE; return true;
} }
/* /*
@@ -6179,76 +6199,78 @@ win_found:
static int autocmd_nested = FALSE; static int autocmd_nested = FALSE;
/* /// Execute autocommands for "event" and file name "fname".
* Execute autocommands for "event" and file name "fname". ///
* Return TRUE if some commands were executed. /// @param event event that occured
*/ /// @param fname filename, NULL or empty means use actual file name
int /// @param fname_io filename to use for <afile> on cmdline
apply_autocmds ( /// @param force When true, ignore autocmd_busy
event_T event, /// @param buf Buffer for <abuf>
char_u *fname, /* NULL or empty means use actual file name */ ///
char_u *fname_io, /* fname to use for <afile> on cmdline */ /// @return true if some commands were executed.
int force, /* when TRUE, ignore autocmd_busy */ bool apply_autocmds(event_T event, char_u *fname, char_u *fname_io, bool force,
buf_T *buf /* buffer for <abuf> */ buf_T *buf)
)
{ {
return apply_autocmds_group(event, fname, fname_io, force, return apply_autocmds_group(event, fname, fname_io, force,
AUGROUP_ALL, buf, NULL); AUGROUP_ALL, buf, NULL);
} }
/* /// Like apply_autocmds(), but with extra "eap" argument. This takes care of
* Like apply_autocmds(), but with extra "eap" argument. This takes care of /// setting v:filearg.
* setting v:filearg. ///
*/ /// @param event event that occured
static int apply_autocmds_exarg(event_T event, char_u *fname, char_u *fname_io, int force, buf_T *buf, exarg_T *eap) /// @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, return apply_autocmds_group(event, fname, fname_io, force,
AUGROUP_ALL, buf, eap); AUGROUP_ALL, buf, eap);
} }
/* /// Like apply_autocmds(), but handles the caller's retval. If the script
* 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
* processing is being aborted or if retval is FAIL when inside a try /// conditional, no autocommands are executed. If otherwise the autocommands
* conditional, no autocommands are executed. If otherwise the autocommands /// cause the script to be aborted, retval is set to FAIL.
* cause the script to be aborted, retval is set to FAIL. ///
*/ /// @param event event that occured
int /// @param fname NULL or empty means use actual file name
apply_autocmds_retval ( /// @param fname_io fname to use for <afile> on cmdline
event_T event, /// @param force When true, ignore autocmd_busy
char_u *fname, /* NULL or empty means use actual file name */ /// @param buf Buffer for <abuf>
char_u *fname_io, /* fname to use for <afile> on cmdline */ /// @param[in,out] retval caller's retval
int force, /* when TRUE, ignore autocmd_busy */ ///
buf_T *buf, /* buffer for <abuf> */ /// @return true if some autocommands were executed
int *retval /* pointer to caller's retval */ 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)) bool did_cmd = apply_autocmds_group(event, fname, fname_io, force,
return FALSE; AUGROUP_ALL, buf, NULL);
if (did_cmd && aborting()) {
did_cmd = apply_autocmds_group(event, fname, fname_io, force,
AUGROUP_ALL, buf, NULL);
if (did_cmd
&& aborting()
)
*retval = FAIL; *retval = FAIL;
}
return did_cmd; return did_cmd;
} }
/* /// Return true when there is a CursorHold/CursorHoldI autocommand defined for
* Return TRUE when there is a CursorHold autocommand defined. /// the current mode.
*/ bool has_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
int has_cursorhold(void)
{ {
return first_autopat[(int)(get_real_state() == NORMAL_BUSY return first_autopat[(int)(get_real_state() == NORMAL_BUSY
? EVENT_CURSORHOLD : EVENT_CURSORHOLDI)] != NULL; ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI)] != NULL;
} }
/* /// Return true if the CursorHold/CursorHoldI event can be triggered.
* Return TRUE if the CursorHold event can be triggered. bool trigger_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
*/
int trigger_cursorhold(void)
{ {
int state; int state;
@@ -6259,10 +6281,11 @@ int trigger_cursorhold(void)
&& !ins_compl_active() && !ins_compl_active()
) { ) {
state = get_real_state(); state = get_real_state();
if (state == NORMAL_BUSY || (state & INSERT) != 0) if (state == NORMAL_BUSY || (state & INSERT) != 0) {
return TRUE; return true;
}
} }
return FALSE; return false;
} }
/// Return true if "event" autocommand is defined. /// Return true if "event" autocommand is defined.
@@ -6273,23 +6296,27 @@ bool has_event(int event) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
return first_autopat[event] != NULL; return first_autopat[event] != NULL;
} }
static int /// Execute autocommands for "event" and file name "fname".
apply_autocmds_group ( ///
event_T event, /// @param event event that occured
char_u *fname, /* NULL or empty means use actual file name */ /// @param fname filename, NULL or empty means use actual file name
char_u *fname_io, /* fname to use for <afile> on cmdline, NULL means /// @param fname_io filename to use for <afile> on cmdline,
use fname */ /// NULL means use `fname`.
int force, /* when TRUE, ignore autocmd_busy */ /// @param force When true, ignore autocmd_busy
int group, /* group ID, or AUGROUP_ALL */ /// @param group autocmd group ID or AUGROUP_ALL
buf_T *buf, /* buffer for <abuf> */ /// @param buf Buffer for <abuf>
exarg_T *eap /* command arguments */ /// @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 *sfname = NULL; /* short file name */
char_u *tail; char_u *tail;
bool save_changed; bool save_changed;
buf_T *old_curbuf; buf_T *old_curbuf;
int retval = FALSE; bool retval = false;
char_u *save_sourcing_name; char_u *save_sourcing_name;
linenr_T save_sourcing_lnum; linenr_T save_sourcing_lnum;
char_u *save_autocmd_fname; char_u *save_autocmd_fname;
@@ -6443,7 +6470,7 @@ apply_autocmds_group (
} }
if (fname == NULL) { /* out of memory */ if (fname == NULL) { /* out of memory */
xfree(sfname); xfree(sfname);
retval = FALSE; retval = false;
goto BYPASS_AU; goto BYPASS_AU;
} }
@@ -6526,17 +6553,19 @@ apply_autocmds_group (
if (eap != NULL) { if (eap != NULL) {
save_cmdarg = set_cmdarg(eap, NULL); save_cmdarg = set_cmdarg(eap, NULL);
set_vim_var_nr(VV_CMDBANG, (long)eap->forceit); set_vim_var_nr(VV_CMDBANG, (long)eap->forceit);
} else } else {
save_cmdarg = NULL; /* avoid gcc warning */ save_cmdarg = NULL; // avoid gcc warning
retval = TRUE; }
/* mark the last pattern, to avoid an endless loop when more patterns retval = true;
* are added when executing autocommands */ // mark the last pattern, to avoid an endless loop when more patterns
for (ap = patcmd.curpat; ap->next != NULL; ap = ap->next) // are added when executing autocommands
ap->last = FALSE; for (ap = patcmd.curpat; ap->next != NULL; ap = ap->next) {
ap->last = TRUE; ap->last = false;
check_lnums(TRUE); /* make sure cursor and topline are valid */ }
ap->last = true;
check_lnums(true); // make sure cursor and topline are valid
do_cmdline(NULL, getnextac, (void *)&patcmd, do_cmdline(NULL, getnextac, (void *)&patcmd,
DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT); DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
if (eap != NULL) { if (eap != NULL) {
(void)set_cmdarg(NULL, save_cmdarg); (void)set_cmdarg(NULL, save_cmdarg);
set_vim_var_nr(VV_CMDBANG, save_cmdbang); set_vim_var_nr(VV_CMDBANG, save_cmdbang);
@@ -6752,21 +6781,25 @@ char_u *getnextac(int c, void *cookie, int indent)
return retval; return retval;
} }
/* /// Return true if there is a matching autocommand for "fname".
* Return TRUE if there is a matching autocommand for "fname". /// To account for buffer-local autocommands, function needs to know
* To account for buffer-local autocommands, function needs to know /// in which buffer the file will be opened.
* in which buffer the file will be opened. ///
*/ /// @param event event that occured.
int has_autocmd(event_T event, char_u *sfname, buf_T *buf) /// @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; AutoPat *ap;
char_u *fname; char_u *fname;
char_u *tail = path_tail(sfname); char_u *tail = path_tail(sfname);
int retval = FALSE; bool retval = false;
fname = (char_u *)FullName_save((char *)sfname, FALSE); fname = (char_u *)FullName_save((char *)sfname, false);
if (fname == NULL) if (fname == NULL) {
return FALSE; return false;
}
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
// Replace all backslashes with forward slashes. This makes the // Replace all backslashes with forward slashes. This makes the
@@ -6776,16 +6809,16 @@ int has_autocmd(event_T event, char_u *sfname, buf_T *buf)
forward_slash(fname); forward_slash(fname);
#endif #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 if (ap->pat != NULL && ap->cmds != NULL
&& (ap->buflocal_nr == 0 && (ap->buflocal_nr == 0
? match_file_pat(NULL, &ap->reg_prog, fname, sfname, tail, ? match_file_pat(NULL, &ap->reg_prog, fname, sfname, tail,
ap->allow_dirs) ap->allow_dirs)
: buf != NULL && ap->buflocal_nr == buf->b_fnum : buf != NULL && ap->buflocal_nr == buf->b_fnum)) {
)) { retval = true;
retval = TRUE;
break; break;
} }
}
xfree(fname); xfree(fname);
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
@@ -6873,29 +6906,27 @@ char_u *get_event_name(expand_T *xp, int idx)
} }
/* /// Return true if autocmd "event" is supported.
* Return TRUE if autocmd is supported. bool autocmd_supported(char_u *event)
*/
int autocmd_supported(char_u *name)
{ {
char_u *p; 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
* Return TRUE if an autocommand is defined for a group, event and /// pattern: The group can be omitted to accept any group.
* pattern: The group can be omitted to accept any group. "event" and "pattern" /// `event` and `pattern` can be omitted to accept any event and pattern.
* can be NULL to accept any event and pattern. "pattern" can be NULL to accept /// Buffer-local patterns <buffer> or <buffer=N> are accepted.
* any pattern. Buffer-local patterns <buffer> or <buffer=N> are accepted. /// Used for:
* Used for: /// exists("#Group") or
* exists("#Group") or /// exists("#Group#Event") or
* exists("#Group#Event") or /// exists("#Group#Event#pat") or
* exists("#Group#Event#pat") or /// exists("#Event") or
* exists("#Event") or /// exists("#Event#pat")
* exists("#Event#pat") ///
*/ /// @param arg autocommand string
int au_exists(char_u *arg) bool au_exists(const char_u *arg) FUNC_ATTR_WARN_UNUSED_RESULT
{ {
char_u *arg_save; char_u *arg_save;
char_u *pattern = NULL; char_u *pattern = NULL;
@@ -6905,7 +6936,7 @@ int au_exists(char_u *arg)
AutoPat *ap; AutoPat *ap;
buf_T *buflocal_buf = NULL; buf_T *buflocal_buf = NULL;
int group; int group;
int retval = FALSE; bool retval = false;
/* Make a copy so that we can change the '#' chars to a NUL. */ /* Make a copy so that we can change the '#' chars to a NUL. */
arg_save = vim_strsave(arg); arg_save = vim_strsave(arg);
@@ -6921,8 +6952,8 @@ int au_exists(char_u *arg)
event_name = arg_save; event_name = arg_save;
} else { } else {
if (p == NULL) { if (p == NULL) {
/* "Group": group name is present and it's recognized */ // "Group": group name is present and it's recognized
retval = TRUE; retval = true;
goto theend; goto theend;
} }
@@ -6964,7 +6995,7 @@ int au_exists(char_u *arg)
|| (buflocal_buf == NULL || (buflocal_buf == NULL
? fnamecmp(ap->pat, pattern) == 0 ? fnamecmp(ap->pat, pattern) == 0
: ap->buflocal_nr == buflocal_buf->b_fnum))) { : ap->buflocal_nr == buflocal_buf->b_fnum))) {
retval = TRUE; retval = true;
break; break;
} }
@@ -6979,12 +7010,13 @@ theend:
/// ///
/// Used for autocommands and 'wildignore'. /// Used for autocommands and 'wildignore'.
/// ///
/// @param pattern the pattern to match with /// @param pattern pattern to match with
/// @param prog the pre-compiled regprog or NULL /// @param prog pre-compiled regprog or NULL
/// @param fname the full path of the file name /// @param fname full path of the file name
/// @param sfname the short file name or NULL /// @param sfname short file name or NULL
/// @param tail the tail of the path /// @param tail tail of the path
/// @param allow_dirs allow matching with dir /// @param allow_dirs Allow matching with dir
///
/// @return true if there is a match, false otherwise /// @return true if there is a match, false otherwise
static bool match_file_pat(char_u *pattern, regprog_T **prog, char_u *fname, static bool match_file_pat(char_u *pattern, regprog_T **prog, char_u *fname,
char_u *sfname, char_u *tail, int allow_dirs) char_u *sfname, char_u *tail, int allow_dirs)
@@ -7023,12 +7055,17 @@ static bool match_file_pat(char_u *pattern, regprog_T **prog, char_u *fname,
return result; return result;
} }
/* /// Check if a file matches with a pattern in "list".
* Return TRUE if a file matches with a pattern in "list". /// "list" is a comma-separated list of patterns, like 'wildignore'.
* "list" is a comma-separated list of patterns, like 'wildignore'. /// "sfname" is the short file name or NULL, "ffname" the long file name.
* "sfname" is the short file name or NULL, "ffname" the long file name. ///
*/ /// @param list list of patterns to match
int match_file_list(char_u *list, char_u *sfname, char_u *ffname) /// @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 buf[100];
char_u *tail; char_u *tail;
@@ -7039,20 +7076,21 @@ int match_file_list(char_u *list, char_u *sfname, char_u *ffname)
tail = path_tail(sfname); tail = path_tail(sfname);
/* try all patterns in 'wildignore' */ // try all patterns in 'wildignore'
p = list; p = list;
while (*p) { while (*p) {
copy_option_part(&p, buf, 100, ","); copy_option_part(&p, buf, ARRAY_SIZE(buf), ",");
regpat = file_pat_to_reg_pat(buf, NULL, &allow_dirs, FALSE); regpat = file_pat_to_reg_pat(buf, NULL, &allow_dirs, false);
if (regpat == NULL) if (regpat == NULL) {
break; 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); xfree(regpat);
if (match) if (match) {
return TRUE; return true;
}
} }
return FALSE; return false;
} }
/// Convert the given pattern "pat" which has shell style wildcards in it, into /// Convert the given pattern "pat" which has shell style wildcards in it, into