refactor: convert macros to all-caps (#17895)

Closes https://github.com/neovim/neovim/issues/6297
This commit is contained in:
dundargoc 2022-04-25 04:18:43 +02:00 committed by GitHub
parent 7813fa2f8c
commit 0648100fed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 143 additions and 147 deletions

View File

@ -9,11 +9,11 @@
// Definitions of various common control characters.
#define CharOrd(x) ((uint8_t)(x) < 'a' \
? (uint8_t)(x) - 'A' \
: (uint8_t)(x) - 'a')
#define CharOrdLow(x) ((uint8_t)(x) - 'a')
#define CharOrdUp(x) ((uint8_t)(x) - 'A')
#define CHAR_ORD(x) ((uint8_t)(x) < 'a' \
? (uint8_t)(x) - 'A' \
: (uint8_t)(x) - 'a')
#define CHAR_ORD_LOW(x) ((uint8_t)(x) - 'a')
#define CHAR_ORD_UP(x) ((uint8_t)(x) - 'A')
#define ROT13(c, a) (((((c) - (a)) + 13) % 26) + (a))
#define NUL '\000'
@ -35,8 +35,8 @@
#define POUND 0xA3
#define Ctrl_chr(x) (TOUPPER_ASC(x) ^ 0x40) // '?' -> DEL, '@' -> ^@, etc.
#define Meta(x) ((x) | 0x80)
#define CTRL_CHR(x) (TOUPPER_ASC(x) ^ 0x40) // '?' -> DEL, '@' -> ^@, etc.
#define META(x) ((x) | 0x80)
#define CTRL_F_STR "\006"
#define CTRL_H_STR "\010"

View File

@ -2359,7 +2359,7 @@ bool au_exists(const char *const arg) FUNC_ATTR_WARN_UNUSED_RESULT
}
// if pattern is "<buffer>", special handling is needed which uses curbuf
// for pattern "<buffer=N>, fnamecmp() will work fine
// for pattern "<buffer=N>, FNAMECMP() will work fine
if (pattern != NULL && STRICMP(pattern, "<buffer>") == 0) {
buflocal_buf = curbuf;
}
@ -2367,12 +2367,12 @@ bool au_exists(const char *const arg) FUNC_ATTR_WARN_UNUSED_RESULT
// Check if there is an autocommand with the given pattern.
for (; ap != NULL; ap = ap->next) {
// only use a pattern when it has not been removed and has commands.
// For buffer-local autocommands, fnamecmp() works fine.
// For buffer-local autocommands, FNAMECMP() works fine.
if (ap->pat != NULL && ap->cmds != NULL
&& (group == AUGROUP_ALL || ap->group == group)
&& (pattern == NULL
|| (buflocal_buf == NULL
? fnamecmp(ap->pat, (char_u *)pattern) == 0
? FNAMECMP(ap->pat, (char_u *)pattern) == 0
: ap->buflocal_nr == buflocal_buf->b_fnum))) {
retval = true;
break;

View File

@ -2955,7 +2955,7 @@ static bool otherfile_buf(buf_T *buf, char_u *ffname, FileID *file_id_p, bool fi
if (ffname == NULL || *ffname == NUL || buf->b_ffname == NULL) {
return true;
}
if (fnamecmp(ffname, buf->b_ffname) == 0) {
if (FNAMECMP(ffname, buf->b_ffname) == 0) {
return false;
}
{

View File

@ -7529,7 +7529,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty)
// Does it look like a control character?
if (*look == '^' && look[1] >= '?' && look[1] <= '_') {
if (try_match && keytyped == Ctrl_chr(look[1])) {
if (try_match && keytyped == CTRL_CHR(look[1])) {
return true;
}
look += 2;
@ -7736,7 +7736,7 @@ int hkmap(int c)
};
if (c == 'N' || c == 'M' || c == 'P' || c == 'C' || c == 'Z') {
return (int)(map[CharOrd(c)] - 1 + p_aleph);
return (int)(map[CHAR_ORD(c)] - 1 + p_aleph);
} else if (c == 'x') { // '-1'='sofit'
return 'X';
} else if (c == 'q') {
@ -7752,7 +7752,7 @@ int hkmap(int c)
// do this the same was as 5.7 and previous, so it works correctly on
// all systems. Specifically, the e.g. Delete and Arrow keys are
// munged and won't work if e.g. searching for Hebrew text.
return (int)(map[CharOrdLow(c)] + p_aleph);
return (int)(map[CHAR_ORD_LOW(c)] + p_aleph);
} else {
return c;
}
@ -7782,12 +7782,12 @@ int hkmap(int c)
if (c < 'a' || c > 'z') {
return c;
}
c = str[CharOrdLow(c)];
c = str[CHAR_ORD_LOW(c)];
break;
}
}
return (int)(CharOrdLow(c) + p_aleph);
return (int)(CHAR_ORD_LOW(c) + p_aleph);
}
}

View File

@ -2720,7 +2720,7 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx)
if (cmdidx == CMD_let || cmdidx == CMD_const) {
xp->xp_context = EXPAND_USER_VARS;
if (vim_strpbrk(arg, (char_u *)"\"'+-*/%.=!?~|&$([<>,#") == NULL) {
if (strpbrk((char *)arg, "\"'+-*/%.=!?~|&$([<>,#") == NULL) {
// ":let var1 var2 ...": find last space.
for (p = arg + STRLEN(arg); p >= arg;) {
xp->xp_pattern = p;
@ -2735,8 +2735,7 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx)
xp->xp_context = cmdidx == CMD_call ? EXPAND_FUNCTIONS
: EXPAND_EXPRESSION;
}
while ((xp->xp_pattern = vim_strpbrk(arg,
(char_u *)"\"'+-*/%.=!?~|&$([<>,#")) != NULL) {
while ((xp->xp_pattern = (char_u *)strpbrk((char *)arg, "\"'+-*/%.=!?~|&$([<>,#")) != NULL) {
c = *xp->xp_pattern;
if (c == '&') {
c = xp->xp_pattern[1];
@ -10202,7 +10201,7 @@ repeat:
// Do not call shorten_fname() here since it removes the prefix
// even though the path does not have a prefix.
if (fnamencmp(p, dirname, namelen) == 0) {
if (FNAMENCMP(p, dirname, namelen) == 0) {
p += namelen;
if (vim_ispathsep(*p)) {
while (*p && vim_ispathsep(*p)) {

View File

@ -29,8 +29,6 @@
#include "nvim/message.h"
#include "nvim/vim.h" // For _()
#define utf_char2len(b) ((size_t)utf_char2len(b))
const char *const encode_bool_var_names[] = {
[kBoolVarTrue] = "true",
[kBoolVarFalse] = "false",
@ -653,7 +651,7 @@ static inline int convert_to_json_string(garray_T *const gap, const char *const
ga_grow(gap, (int)str_len);
for (size_t i = 0; i < utf_len;) {
const int ch = utf_ptr2char((char_u *)utf_buf + i);
const size_t shift = (ch == 0? 1: utf_char2len(ch));
const size_t shift = (ch == 0 ? 1 : ((size_t)utf_char2len(ch)));
assert(shift > 0);
// Is false on invalid unicode, but this should already be handled.
assert(ch == 0 || shift == ((size_t)utf_ptr2len((char_u *)utf_buf + i)));

View File

@ -2503,7 +2503,7 @@ void ex_function(exarg_T *eap)
p = vim_strchr(scriptname, '/');
plen = (int)STRLEN(p);
slen = (int)STRLEN(sourcing_name);
if (slen > plen && fnamecmp(p,
if (slen > plen && FNAMECMP(p,
sourcing_name + slen - plen) == 0) {
j = OK;
}

View File

@ -10,8 +10,8 @@
typedef void *WatcherPtr;
#define _noop(x)
KLIST_INIT(WatcherPtr, WatcherPtr, _noop)
#define _NOOP(x)
KLIST_INIT(WatcherPtr, WatcherPtr, _NOOP)
typedef struct loop {
uv_loop_t uv;

View File

@ -5343,8 +5343,8 @@ void fix_help_buffer(void)
* files. This uses the very first line in the help file.
*/
char_u *const fname = path_tail(curbuf->b_fname);
if (fnamecmp(fname, "help.txt") == 0
|| (fnamencmp(fname, "help.", 5) == 0
if (FNAMECMP(fname, "help.txt") == 0
|| (FNAMENCMP(fname, "help.", 5) == 0
&& ASCII_ISALPHA(fname[5])
&& ASCII_ISALPHA(fname[6])
&& TOLOWER_ASC(fname[7]) == 'x'
@ -5402,18 +5402,18 @@ void fix_help_buffer(void)
if (e1 == NULL || e2 == NULL) {
continue;
}
if (fnamecmp(e1, ".txt") != 0
&& fnamecmp(e1, fname + 4) != 0) {
if (FNAMECMP(e1, ".txt") != 0
&& FNAMECMP(e1, fname + 4) != 0) {
// Not .txt and not .abx, remove it.
XFREE_CLEAR(fnames[i1]);
continue;
}
if (e1 - f1 != e2 - f2
|| fnamencmp(f1, f2, e1 - f1) != 0) {
|| FNAMENCMP(f1, f2, e1 - f1) != 0) {
continue;
}
if (fnamecmp(e1, ".txt") == 0
&& fnamecmp(e2, fname + 4) == 0) {
if (FNAMECMP(e1, ".txt") == 0
&& FNAMECMP(e2, fname + 4) == 0) {
// use .abx instead of .txt
XFREE_CLEAR(fnames[i1]);
}

View File

@ -2179,7 +2179,7 @@ scriptitem_T *get_current_script_id(char_u *fname, sctx_T *ret_sctx)
bool file_id_equal = file_id_ok && si->file_id_valid
&& os_fileid_equal(&(si->file_id), &file_id);
if (si->sn_name != NULL
&& (file_id_equal || fnamecmp(si->sn_name, fname) == 0)) {
&& (file_id_equal || FNAMECMP(si->sn_name, fname) == 0)) {
break;
}
}

View File

@ -44,8 +44,8 @@
#include "nvim/keymap.h"
#include "nvim/lua/executor.h"
#include "nvim/main.h"
#include "nvim/match.h"
#include "nvim/mark.h"
#include "nvim/match.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
@ -2663,9 +2663,9 @@ static char_u *find_command(exarg_T *eap, int *full)
// Use a precomputed index for fast look-up in cmdnames[]
// taking into account the first 2 letters of eap->cmd.
eap->cmdidx = cmdidxs1[CharOrdLow(c1)];
eap->cmdidx = cmdidxs1[CHAR_ORD_LOW(c1)];
if (ASCII_ISLOWER(c2)) {
eap->cmdidx += cmdidxs2[CharOrdLow(c1)][CharOrdLow(c2)];
eap->cmdidx += cmdidxs2[CHAR_ORD_LOW(c1)][CHAR_ORD_LOW(c2)];
}
} else {
eap->cmdidx = CMD_bang;
@ -4519,7 +4519,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char **errormsgp)
if ((eap->usefilter
|| eap->cmdidx == CMD_bang
|| eap->cmdidx == CMD_terminal)
&& vim_strpbrk(repl, (char_u *)"!") != NULL) {
&& strpbrk((char *)repl, "!") != NULL) {
char_u *l;
l = vim_strsave_escaped(repl, (char_u *)"!");

View File

@ -75,7 +75,10 @@
|| (cstack->cs_idx > 0 \
&& !(cstack->cs_flags[cstack->cs_idx - 1] & CSF_ACTIVE)))
#define discard_pending_return(p) tv_free((typval_T *)(p))
static void discard_pending_return(typval_T *p)
{
tv_free(p);
}
/*
* When several errors appear in a row, setting "force_abort" is delayed until

View File

@ -924,8 +924,8 @@ char_u *vim_findfile(void *search_ctx_arg)
*/
if (STRNCMP(stackp->ffs_wc_path, "**", 2) == 0) {
for (int i = stackp->ffs_filearray_cur;
i < stackp->ffs_filearray_size; ++i) {
if (fnamecmp(stackp->ffs_filearray[i],
i < stackp->ffs_filearray_size; i++) {
if (FNAMECMP(stackp->ffs_filearray[i],
stackp->ffs_fix_path) == 0) {
continue; // don't repush same directory
}
@ -1050,7 +1050,7 @@ static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename,
if (*list_headp != NULL) {
retptr = *list_headp;
while (retptr != NULL) {
if (fnamecmp(filename, retptr->ffvl_filename) == 0) {
if (FNAMECMP(filename, retptr->ffvl_filename) == 0) {
#ifdef FF_VERBOSE
if (p_verbose >= 5) {
verbose_enter_scroll();
@ -1151,7 +1151,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *
// check against list of already visited files
for (vp = *visited_list; vp != NULL; vp = vp->ffv_next) {
if ((url && fnamecmp(vp->ffv_fname, ff_expand_buffer) == 0)
if ((url && FNAMECMP(vp->ffv_fname, ff_expand_buffer) == 0)
|| (!url && vp->file_id_valid
&& os_fileid_equal(&(vp->file_id), &file_id))) {
// are the wildcard parts equal
@ -1317,13 +1317,13 @@ static int ff_path_in_stoplist(char_u *path, int path_len, char_u **stopdirs_v)
* '/home/rks'. Check for PATHSEP in stopdirs_v[i], else
* '/home/r' would also match '/home/rks'
*/
if (fnamencmp(stopdirs_v[i], path, path_len) == 0
if (FNAMENCMP(stopdirs_v[i], path, path_len) == 0
&& vim_ispathsep(stopdirs_v[i][path_len])) {
return TRUE;
}
} else {
if (fnamecmp(stopdirs_v[i], path) == 0) {
return TRUE;
if (FNAMECMP(stopdirs_v[i], path) == 0) {
return true;
}
}
}

View File

@ -2321,8 +2321,8 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_
fname = sfname;
#endif
if (buf->b_ffname != NULL && fnamecmp(ffname, buf->b_ffname) == 0) {
overwriting = TRUE;
if (buf->b_ffname != NULL && FNAMECMP(ffname, buf->b_ffname) == 0) {
overwriting = true;
} else {
overwriting = FALSE;
}
@ -4647,7 +4647,7 @@ int vim_rename(const char_u *from, const char_u *to)
* to the same file (ignoring case and slash/backslash differences) but
* the file name differs we need to go through a temp file.
*/
if (fnamecmp(from, to) == 0) {
if (FNAMECMP(from, to) == 0) {
if (p_fic && (STRCMP(path_tail((char_u *)from), path_tail((char_u *)to))
!= 0)) {
use_tmp_file = true;

View File

@ -123,7 +123,7 @@ void ga_remove_duplicate_strings(garray_T *gap)
// loop over the growing array in reverse
for (int i = gap->ga_len - 1; i > 0; i--) {
if (fnamecmp(fnames[i - 1], fnames[i]) == 0) {
if (FNAMECMP(fnames[i - 1], fnames[i]) == 0) {
xfree(fnames[i]);
// close the gap (move all strings one slot lower)

View File

@ -1869,8 +1869,6 @@ static void prt_dsc_text(char *comment, char *text)
prt_write_file(prt_line_buffer);
}
#define prt_dsc_atend(c) prt_dsc_text((c), "atend")
static void prt_dsc_ints(char *comment, int count, int *ints)
{
int i;
@ -2534,7 +2532,7 @@ bool mch_print_begin(prt_settings_T *psettings)
prt_dsc_textline("CreationDate", p_time);
prt_dsc_textline("DocumentData", "Clean8Bit");
prt_dsc_textline("Orientation", "Portrait");
prt_dsc_atend("Pages");
prt_dsc_text(("Pages"), "atend");
prt_dsc_textline("PageOrder", "Ascend");
// The bbox does not change with orientation - it is always in the default
// user coordinate system! We have to recalculate right and bottom

View File

@ -775,7 +775,7 @@ static int extract_modifiers(int key, int *modp)
}
if ((modifiers & MOD_MASK_CTRL) && ((key >= '?' && key <= '_') || ASCII_ISALPHA(key))) {
key = TOUPPER_ASC(key);
int new_key = Ctrl_chr(key);
int new_key = CTRL_CHR(key);
if (new_key != TAB && new_key != CAR && new_key != ESC) {
key = new_key;
modifiers &= ~MOD_MASK_CTRL;

View File

@ -83,11 +83,11 @@
// mch_open_rw(): invoke os_open() with third argument for user R/W.
#if defined(UNIX) // open in rw------- mode
# define mch_open_rw(n, f) os_open((n), (f), (mode_t)0600)
# define MCH_OPEN_RW(n, f) os_open((n), (f), (mode_t)0600)
#elif defined(WIN32)
# define mch_open_rw(n, f) os_open((n), (f), S_IREAD | S_IWRITE)
# define MCH_OPEN_RW(n, f) os_open((n), (f), S_IREAD | S_IWRITE)
#else
# define mch_open_rw(n, f) os_open((n), (f), 0)
# define MCH_OPEN_RW(n, f) os_open((n), (f), 0)
#endif
#define REPLACE_NORMAL(s) (((s) & REPLACE_FLAG) && !((s) & VREPLACE_FLAG))

View File

@ -551,7 +551,7 @@ static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf)
{
if (fm->fmark.fnum == 0
&& fm->fname != NULL
&& fnamecmp(name, fm->fname) == 0) {
&& FNAMECMP(name, fm->fname) == 0) {
fm->fmark.fnum = buf->b_fnum;
XFREE_CLEAR(fm->fname);
}
@ -923,7 +923,7 @@ void ex_changes(exarg_T *eap)
}
}
#define one_adjust(add) \
#define ONE_ADJUST(add) \
{ \
lp = add; \
if (*lp >= line1 && *lp <= line2) \
@ -938,7 +938,7 @@ void ex_changes(exarg_T *eap)
}
// don't delete the line, just put at first deleted line
#define one_adjust_nodel(add) \
#define ONE_ADJUST_NODEL(add) \
{ \
lp = add; \
if (*lp >= line1 && *lp <= line2) \
@ -994,37 +994,37 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, lo
if (!cmdmod.lockmarks) {
// named marks, lower case and upper case
for (i = 0; i < NMARKS; i++) {
one_adjust(&(curbuf->b_namedm[i].mark.lnum));
ONE_ADJUST(&(curbuf->b_namedm[i].mark.lnum));
if (namedfm[i].fmark.fnum == fnum) {
one_adjust_nodel(&(namedfm[i].fmark.mark.lnum));
ONE_ADJUST_NODEL(&(namedfm[i].fmark.mark.lnum));
}
}
for (i = NMARKS; i < NGLOBALMARKS; i++) {
if (namedfm[i].fmark.fnum == fnum) {
one_adjust_nodel(&(namedfm[i].fmark.mark.lnum));
ONE_ADJUST_NODEL(&(namedfm[i].fmark.mark.lnum));
}
}
// last Insert position
one_adjust(&(curbuf->b_last_insert.mark.lnum));
ONE_ADJUST(&(curbuf->b_last_insert.mark.lnum));
// last change position
one_adjust(&(curbuf->b_last_change.mark.lnum));
ONE_ADJUST(&(curbuf->b_last_change.mark.lnum));
// last cursor position, if it was set
if (!equalpos(curbuf->b_last_cursor.mark, initpos)) {
one_adjust(&(curbuf->b_last_cursor.mark.lnum));
ONE_ADJUST(&(curbuf->b_last_cursor.mark.lnum));
}
// list of change positions
for (i = 0; i < curbuf->b_changelistlen; ++i) {
one_adjust_nodel(&(curbuf->b_changelist[i].mark.lnum));
for (i = 0; i < curbuf->b_changelistlen; i++) {
ONE_ADJUST_NODEL(&(curbuf->b_changelist[i].mark.lnum));
}
// Visual area
one_adjust_nodel(&(curbuf->b_visual.vi_start.lnum));
one_adjust_nodel(&(curbuf->b_visual.vi_end.lnum));
ONE_ADJUST_NODEL(&(curbuf->b_visual.vi_start.lnum));
ONE_ADJUST_NODEL(&(curbuf->b_visual.vi_end.lnum));
// quickfix marks
if (!qf_mark_adjust(NULL, line1, line2, amount, amount_after)) {
@ -1047,14 +1047,14 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, lo
}
// previous context mark
one_adjust(&(curwin->w_pcmark.lnum));
ONE_ADJUST(&(curwin->w_pcmark.lnum));
// previous pcmark
one_adjust(&(curwin->w_prev_pcmark.lnum));
ONE_ADJUST(&(curwin->w_prev_pcmark.lnum));
// saved cursor for formatting
if (saved_cursor.lnum != 0) {
one_adjust_nodel(&(saved_cursor.lnum));
ONE_ADJUST_NODEL(&(saved_cursor.lnum));
}
/*
@ -1066,7 +1066,7 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, lo
// duplicate marks in the jumplist, they will be removed later.
for (i = 0; i < win->w_jumplistlen; i++) {
if (win->w_jumplist[i].fmark.fnum == fnum) {
one_adjust_nodel(&(win->w_jumplist[i].fmark.mark.lnum));
ONE_ADJUST_NODEL(&(win->w_jumplist[i].fmark.mark.lnum));
}
}
}
@ -1076,15 +1076,15 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, lo
// marks in the tag stack
for (i = 0; i < win->w_tagstacklen; i++) {
if (win->w_tagstack[i].fmark.fnum == fnum) {
one_adjust_nodel(&(win->w_tagstack[i].fmark.mark.lnum));
ONE_ADJUST_NODEL(&(win->w_tagstack[i].fmark.mark.lnum));
}
}
}
// the displayed Visual area
if (win->w_old_cursor_lnum != 0) {
one_adjust_nodel(&(win->w_old_cursor_lnum));
one_adjust_nodel(&(win->w_old_visual_lnum));
ONE_ADJUST_NODEL(&(win->w_old_cursor_lnum));
ONE_ADJUST_NODEL(&(win->w_old_visual_lnum));
}
// topline and cursor position for windows with the same buffer
@ -1132,7 +1132,7 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, lo
}
// This code is used often, needs to be fast.
#define col_adjust(pp) \
#define COL_ADJUST(pp) \
{ \
posp = pp; \
if (posp->lnum == lnum && posp->col >= mincol) \
@ -1166,40 +1166,40 @@ void mark_col_adjust(linenr_T lnum, colnr_T mincol, long lnum_amount, long col_a
}
// named marks, lower case and upper case
for (i = 0; i < NMARKS; i++) {
col_adjust(&(curbuf->b_namedm[i].mark));
COL_ADJUST(&(curbuf->b_namedm[i].mark));
if (namedfm[i].fmark.fnum == fnum) {
col_adjust(&(namedfm[i].fmark.mark));
COL_ADJUST(&(namedfm[i].fmark.mark));
}
}
for (i = NMARKS; i < NGLOBALMARKS; i++) {
if (namedfm[i].fmark.fnum == fnum) {
col_adjust(&(namedfm[i].fmark.mark));
COL_ADJUST(&(namedfm[i].fmark.mark));
}
}
// last Insert position
col_adjust(&(curbuf->b_last_insert.mark));
COL_ADJUST(&(curbuf->b_last_insert.mark));
// last change position
col_adjust(&(curbuf->b_last_change.mark));
COL_ADJUST(&(curbuf->b_last_change.mark));
// list of change positions
for (i = 0; i < curbuf->b_changelistlen; ++i) {
col_adjust(&(curbuf->b_changelist[i].mark));
for (i = 0; i < curbuf->b_changelistlen; i++) {
COL_ADJUST(&(curbuf->b_changelist[i].mark));
}
// Visual area
col_adjust(&(curbuf->b_visual.vi_start));
col_adjust(&(curbuf->b_visual.vi_end));
COL_ADJUST(&(curbuf->b_visual.vi_start));
COL_ADJUST(&(curbuf->b_visual.vi_end));
// previous context mark
col_adjust(&(curwin->w_pcmark));
COL_ADJUST(&(curwin->w_pcmark));
// previous pcmark
col_adjust(&(curwin->w_prev_pcmark));
COL_ADJUST(&(curwin->w_prev_pcmark));
// saved cursor for formatting
col_adjust(&saved_cursor);
COL_ADJUST(&saved_cursor);
/*
* Adjust items in all windows related to the current buffer.
@ -1208,7 +1208,7 @@ void mark_col_adjust(linenr_T lnum, colnr_T mincol, long lnum_amount, long col_a
// marks in the jumplist
for (i = 0; i < win->w_jumplistlen; ++i) {
if (win->w_jumplist[i].fmark.fnum == fnum) {
col_adjust(&(win->w_jumplist[i].fmark.mark));
COL_ADJUST(&(win->w_jumplist[i].fmark.mark));
}
}
@ -1216,13 +1216,13 @@ void mark_col_adjust(linenr_T lnum, colnr_T mincol, long lnum_amount, long col_a
// marks in the tag stack
for (i = 0; i < win->w_tagstacklen; i++) {
if (win->w_tagstack[i].fmark.fnum == fnum) {
col_adjust(&(win->w_tagstack[i].fmark.mark));
COL_ADJUST(&(win->w_tagstack[i].fmark.mark));
}
}
// cursor position for other windows with the same buffer
if (win != curwin) {
col_adjust(&win->w_cursor);
COL_ADJUST(&win->w_cursor);
}
}
}

View File

@ -795,7 +795,7 @@ static bool mf_do_open(memfile_T *mfp, char_u *fname, int flags)
emsg(_("E300: Swap file already exists (symlink attack?)"));
} else {
// try to open the file
mfp->mf_fd = mch_open_rw((char *)mfp->mf_fname, flags | O_NOFOLLOW);
mfp->mf_fd = MCH_OPEN_RW((char *)mfp->mf_fname, flags | O_NOFOLLOW);
}
// If the file cannot be opened, use memory only

View File

@ -418,7 +418,7 @@ void ml_setname(buf_T *buf)
}
// if the file name is the same we don't have to do anything
if (fnamecmp(fname, mfp->mf_fname) == 0) {
if (FNAMECMP(fname, mfp->mf_fname) == 0) {
xfree(fname);
success = true;
break;
@ -3459,7 +3459,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_
}
// A file name equal to old_fname is OK to use.
if (old_fname != NULL && fnamecmp(fname, old_fname) == 0) {
if (old_fname != NULL && FNAMECMP(fname, old_fname) == 0) {
break;
}
@ -3484,7 +3484,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_
// buffer don't compare the directory names, they can
// have a different mountpoint.
if (b0.b0_flags & B0_SAME_DIR) {
if (fnamecmp(path_tail(buf->b_ffname),
if (FNAMECMP(path_tail(buf->b_ffname),
path_tail(b0.b0_fname)) != 0
|| !same_directory((char_u *)fname, buf->b_ffname)) {
// Symlinks may point to the same file even

View File

@ -5146,7 +5146,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
if (do_alpha && ASCII_ISALPHA(firstdigit)) {
// decrement or increment alphabetic character
if (op_type == OP_NR_SUB) {
if (CharOrd(firstdigit) < Prenum1) {
if (CHAR_ORD(firstdigit) < Prenum1) {
if (isupper(firstdigit)) {
firstdigit = 'A';
} else {
@ -5156,7 +5156,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
firstdigit -= (int)Prenum1;
}
} else {
if (26 - CharOrd(firstdigit) - 1 < Prenum1) {
if (26 - CHAR_ORD(firstdigit) - 1 < Prenum1) {
if (isupper(firstdigit)) {
firstdigit = 'Z';
} else {

View File

@ -108,9 +108,9 @@ static inline int op_reg_index(const int regname)
if (ascii_isdigit(regname)) {
return regname - '0';
} else if (ASCII_ISLOWER(regname)) {
return CharOrdLow(regname) + 10;
return CHAR_ORD_LOW(regname) + 10;
} else if (ASCII_ISUPPER(regname)) {
return CharOrdUp(regname) + 10;
return CHAR_ORD_UP(regname) + 10;
} else if (regname == '-') {
return DELETION_REGISTER;
} else if (regname == '*') {

View File

@ -832,8 +832,8 @@ void set_init_3(void)
// Default for p_sp is "| tee", for p_srr is ">".
// For known shells it is changed here to include stderr.
//
if (fnamecmp(p, "csh") == 0
|| fnamecmp(p, "tcsh") == 0) {
if (FNAMECMP(p, "csh") == 0
|| FNAMECMP(p, "tcsh") == 0) {
if (do_sp) {
p_sp = (char_u *)"|& tee";
options[idx_sp].def_val = p_sp;
@ -842,16 +842,16 @@ void set_init_3(void)
p_srr = (char_u *)">&";
options[idx_srr].def_val = p_srr;
}
} else if (fnamecmp(p, "sh") == 0
|| fnamecmp(p, "ksh") == 0
|| fnamecmp(p, "mksh") == 0
|| fnamecmp(p, "pdksh") == 0
|| fnamecmp(p, "zsh") == 0
|| fnamecmp(p, "zsh-beta") == 0
|| fnamecmp(p, "bash") == 0
|| fnamecmp(p, "fish") == 0
|| fnamecmp(p, "ash") == 0
|| fnamecmp(p, "dash") == 0) {
} else if (FNAMECMP(p, "sh") == 0
|| FNAMECMP(p, "ksh") == 0
|| FNAMECMP(p, "mksh") == 0
|| FNAMECMP(p, "pdksh") == 0
|| FNAMECMP(p, "zsh") == 0
|| FNAMECMP(p, "zsh-beta") == 0
|| FNAMECMP(p, "bash") == 0
|| FNAMECMP(p, "fish") == 0
|| FNAMECMP(p, "ash") == 0
|| FNAMECMP(p, "dash") == 0) {
// Always use POSIX shell style redirection if we reach this
if (do_sp) {
p_sp = (char_u *)"2>&1| tee";
@ -1799,7 +1799,7 @@ static int string_to_key(char_u *arg)
return find_key_option(arg + 1, true);
}
if (*arg == '^') {
return Ctrl_chr(arg[1]);
return CTRL_CHR(arg[1]);
}
return *arg;
}
@ -2392,10 +2392,10 @@ static char *did_set_string_option(int opt_idx, char_u **varp, bool new_value_al
&& (options[opt_idx].flags & P_SECURE)) {
errmsg = e_secure;
} else if (((options[opt_idx].flags & P_NFNAME)
&& vim_strpbrk(*varp, (char_u *)(secure ? "/\\*?[|;&<>\r\n"
: "/\\*?[<>\r\n")) != NULL)
&& strpbrk((char *)(*varp),
(secure ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
|| ((options[opt_idx].flags & P_NDNAME)
&& vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL)) {
&& strpbrk((char *)(*varp), "*?[|;&<>\r\n") != NULL)) {
// Check for a "normal" directory or file name in some options. Disallow a
// path separator (slash and/or backslash), wildcards and characters that
// are often illegal in a file name. Be more permissive if "secure" is off.
@ -4799,7 +4799,7 @@ int findoption_len(const char *const arg, const size_t len)
if (s[0] == 't' && s[1] == '_') {
quick_tab[26] = i;
} else {
quick_tab[CharOrdLow(s[0])] = i;
quick_tab[CHAR_ORD_LOW(s[0])] = i;
}
}
p = s;
@ -4816,7 +4816,7 @@ int findoption_len(const char *const arg, const size_t len)
if (is_term_opt) {
opt_idx = quick_tab[26];
} else {
opt_idx = quick_tab[CharOrdLow(arg[0])];
opt_idx = quick_tab[CHAR_ORD_LOW(arg[0])];
}
// Match full name
for (; (s = options[opt_idx].fullname) != NULL; opt_idx++) {
@ -4825,7 +4825,7 @@ int findoption_len(const char *const arg, const size_t len)
}
}
if (s == NULL && !is_term_opt) {
opt_idx = quick_tab[CharOrdLow(arg[0])];
opt_idx = quick_tab[CHAR_ORD_LOW(arg[0])];
// Match short name
for (; options[opt_idx].fullname != NULL; opt_idx++) {
s = options[opt_idx].shortname;

View File

@ -698,7 +698,7 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo
// 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) {
if (esc && var != NULL && strpbrk((char *)var, " \t") != NULL) {
char_u *p = vim_strsave_escaped(var, (char_u *)" \t");
if (mustfree) {
@ -805,7 +805,7 @@ static char *remove_tail(char *path, char *pend, char *dirname)
char *new_tail = pend - len - 1;
if (new_tail >= path
&& fnamencmp((char_u *)new_tail, (char_u *)dirname, len) == 0
&& FNAMENCMP((char_u *)new_tail, (char_u *)dirname, len) == 0
&& (new_tail == path || after_pathsep(path, new_tail))) {
return new_tail;
}
@ -1102,7 +1102,7 @@ size_t home_replace(const buf_T *const buf, const char_u *src, char_u *const dst
size_t len = dirlen;
for (;;) {
if (len
&& fnamencmp(src, (char_u *)p, len) == 0
&& FNAMENCMP(src, (char_u *)p, len) == 0
&& (vim_ispathsep(src[len])
|| (!one && (src[len] == ',' || src[len] == ' '))
|| src[len] == NUL)) {

View File

@ -1293,7 +1293,7 @@ shortcut_end:
return rfname;
}
# define is_path_sep(c) ((c) == L'\\' || (c) == L'/')
# define IS_PATH_SEP(c) ((c) == L'\\' || (c) == L'/')
/// Returns true if the path contains a reparse point (junction or symbolic
/// link). Otherwise false in returned.
bool os_is_reparse_point_include(const char *path)
@ -1310,9 +1310,9 @@ bool os_is_reparse_point_include(const char *path)
}
p = utf16_path;
if (isalpha(p[0]) && p[1] == L':' && is_path_sep(p[2])) {
if (isalpha(p[0]) && p[1] == L':' && IS_PATH_SEP(p[2])) {
p += 3;
} else if (is_path_sep(p[0]) && is_path_sep(p[1])) {
} else if (IS_PATH_SEP(p[0]) && IS_PATH_SEP(p[1])) {
p += 2;
}

View File

@ -71,9 +71,9 @@ FileComparison path_full_compare(char_u *const s1, char_u *const s2, const bool
if (!id_ok_1 && !id_ok_2) {
// If os_fileid() doesn't work, may compare the names.
if (checkname) {
vim_FullName((char *)exp1, (char *)full1, MAXPATHL, FALSE);
vim_FullName((char *)s2, (char *)full2, MAXPATHL, FALSE);
if (fnamecmp(full1, full2) == 0) {
vim_FullName((char *)exp1, (char *)full1, MAXPATHL, false);
vim_FullName((char *)s2, (char *)full2, MAXPATHL, false);
if (FNAMECMP(full1, full2) == 0) {
return kEqualFileNames;
}
}
@ -728,7 +728,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff,
&& (name[1] != '.' || name[2] != NUL))) // -V557
&& ((regmatch.regprog != NULL && vim_regexec(&regmatch, name, 0))
|| ((flags & EW_NOTWILD)
&& fnamencmp(path + (s - buf), name, e - s) == 0))) {
&& FNAMENCMP(path + (s - buf), name, e - s) == 0))) {
STRCPY(s, name);
len = STRLEN(buf);
@ -817,7 +817,7 @@ static bool is_unique(char_u *maybe_unique, garray_T *gap, int i)
continue; // it's different when it's shorter
}
char_u *rival = other_paths[j] + other_path_len - candidate_len;
if (fnamecmp(maybe_unique, rival) == 0
if (FNAMECMP(maybe_unique, rival) == 0
&& (rival == other_paths[j] || vim_ispathsep(*(rival - 1)))) {
return false; // match
}
@ -976,7 +976,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
char_u *path_cutoff;
len = STRLEN(path);
is_in_curdir = fnamencmp(curdir, path, dir_end - path) == 0
is_in_curdir = FNAMENCMP(curdir, path, dir_end - path) == 0
&& curdir[dir_end - path] == NUL;
if (is_in_curdir) {
in_curdir[i] = vim_strsave(path);
@ -1473,7 +1473,7 @@ void addfile(garray_T *gap, char_u *f, int flags)
#ifdef FNAME_ILLEGAL
// if the file/dir contains illegal characters, don't add it
if (vim_strpbrk(f, (char_u *)FNAME_ILLEGAL) != NULL) {
if (strpbrk((char *)f, FNAME_ILLEGAL) != NULL) {
return;
}
#endif
@ -2090,7 +2090,7 @@ char_u *path_shorten_fname(char_u *full_path, char_u *dir_name)
// If full_path and dir_name do not match, it's impossible to make one
// relative to the other.
if (fnamencmp(dir_name, full_path, len) != 0) {
if (FNAMENCMP(dir_name, full_path, len) != 0) {
return NULL;
}
@ -2254,7 +2254,7 @@ int match_suffix(char_u *fname)
}
} else {
if (fnamelen >= setsuflen
&& fnamencmp(suf_buf, fname + fnamelen - setsuflen, setsuflen) == 0) {
&& FNAMENCMP(suf_buf, fname + fnamelen - setsuflen, setsuflen) == 0) {
break;
}
setsuflen = 0;

View File

@ -2324,7 +2324,7 @@ int check_linecomment(const char_u *line)
if (vim_strchr(p, ';') != NULL) { // there may be comments
bool in_str = false; // inside of string
while ((p = vim_strpbrk(p, (char_u *)"\";")) != NULL) {
while ((p = (char_u *)strpbrk((char *)p, "\";")) != NULL) {
if (*p == '"') {
if (in_str) {
if (*(p - 1) != '\\') { // skip escaped quote

View File

@ -1053,7 +1053,7 @@ static buf_T *find_buffer(khash_t(fnamebufs) *const fname_bufs, const char *cons
kh_key(fname_bufs, k) = xstrdup(fname);
FOR_ALL_BUFFERS(buf) {
if (buf->b_ffname != NULL) {
if (fnamecmp(fname, buf->b_ffname) == 0) {
if (FNAMECMP(fname, buf->b_ffname) == 0) {
kh_val(fname_bufs, k) = buf;
return buf;
}

View File

@ -2101,7 +2101,7 @@ char *did_set_spelllang(win_T *wp)
// If the name ends in ".spl" use it as the name of the spell file.
// If there is a region name let "region" point to it and remove it
// from the name.
if (len > 4 && fnamecmp(lang + len - 4, ".spl") == 0) {
if (len > 4 && FNAMECMP(lang + len - 4, ".spl") == 0) {
filename = true;
// Locate a region and remove it from the file name.

View File

@ -893,7 +893,7 @@ void suggest_load_files(void)
slang->sl_sugloaded = true;
dotp = STRRCHR(slang->sl_fname, '.');
if (dotp == NULL || fnamecmp(dotp, ".spl") != 0) {
if (dotp == NULL || FNAMECMP(dotp, ".spl") != 0) {
continue;
}
STRCPY(dotp, ".sug");

View File

@ -5376,7 +5376,7 @@ static int get_id_list(char_u **const arg, const int keylen, int16_t **const lis
/*
* Handle full group name.
*/
if (vim_strpbrk(name + 1, (char_u *)"\\.*^$~[") == NULL) {
if (strpbrk((char *)name + 1, "\\.*^$~[") == NULL) {
id = syn_check_group((char *)(name + 1), (int)(end - p));
} else {
// Handle match of regexp with group names.

View File

@ -253,8 +253,6 @@ enum { FOLD_TEXT_LEN = 51, }; //!< buffer size for get_foldtext()
#define STRNCAT(d, s, n) strncat((char *)(d), (char *)(s), (size_t)(n))
#define STRLCAT(d, s, n) xstrlcat((char *)(d), (char *)(s), (size_t)(n))
#define vim_strpbrk(s, cs) (char_u *)strpbrk((char *)(s), (char *)(cs))
// Character used as separated in autoload function/variable names.
#define AUTOLOAD_CHAR '#'
@ -280,8 +278,8 @@ enum { FOLD_TEXT_LEN = 51, }; //!< buffer size for get_foldtext()
/// @param[in] y Second file name to compare.
///
/// @return 0 for equal file names, non-zero otherwise.
#define fnamecmp(x, y) path_fnamecmp((const char *)(x), (const char *)(y))
#define fnamencmp(x, y, n) path_fnamencmp((const char *)(x), \
#define FNAMECMP(x, y) path_fnamecmp((const char *)(x), (const char *)(y))
#define FNAMENCMP(x, y, n) path_fnamencmp((const char *)(x), \
(const char *)(y), \
(size_t)(n))

View File

@ -66,7 +66,7 @@
#include "nvim/viml/parser/expressions.h"
#include "nvim/viml/parser/parser.h"
#define vim_str2nr(s, ...) vim_str2nr((const char_u *)(s), __VA_ARGS__)
#define VIM_STR2NR(s, ...) vim_str2nr((const char_u *)(s), __VA_ARGS__)
typedef kvec_withinit_t(ExprASTNode **, 16) ExprASTStack;
@ -371,7 +371,7 @@ LexExprToken viml_pexpr_next_token(ParserState *const pstate, const int flags)
significand_part = significand_part * 10 + (pline.data[i] - '0');
}
if (exp_start) {
vim_str2nr(pline.data + exp_start, NULL, NULL, 0, NULL, &exp_part,
VIM_STR2NR(pline.data + exp_start, NULL, NULL, 0, NULL, &exp_part,
(int)(ret.len - exp_start), false);
}
if (exp_negative) {
@ -389,7 +389,7 @@ LexExprToken viml_pexpr_next_token(ParserState *const pstate, const int flags)
} else {
int len;
int prep;
vim_str2nr(pline.data, &prep, &len, STR2NR_ALL, NULL,
VIM_STR2NR(pline.data, &prep, &len, STR2NR_ALL, NULL,
&ret.data.num.val.integer, (int)pline.size, false);
ret.len = (size_t)len;
const uint8_t bases[] = {