aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c42
-rw-r--r--src/nvim/syntax.c2
-rw-r--r--src/nvim/version.c57
3 files changed, 72 insertions, 29 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 76f33e7d8c..9cd9b5c8b4 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -10524,16 +10524,10 @@ static void f_glob2regpat(typval_T *argvars, typval_T *rettv, FunPtr fptr)
: file_pat_to_reg_pat(pat, NULL, NULL, false);
}
-/*
- * "has()" function
- */
+/// "has()" function
static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- int i;
- char_u *name;
- int n = FALSE;
- static char *(has_list[]) =
- {
+ static char *(has_list[]) = {
#ifdef UNIX
"unix",
#endif
@@ -10646,36 +10640,44 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
NULL
};
- name = get_tv_string(&argvars[0]);
- for (i = 0; has_list[i] != NULL; ++i)
+ bool n = false;
+ char *name = (char *)get_tv_string(&argvars[0]);
+
+ for (int i = 0; has_list[i] != NULL; i++) {
if (STRICMP(name, has_list[i]) == 0) {
- n = TRUE;
+ n = true;
break;
}
+ }
- if (n == FALSE) {
+ if (!n) {
if (STRNICMP(name, "patch", 5) == 0) {
if (name[5] == '-'
- && STRLEN(name) > 11
+ && strlen(name) > 11
&& ascii_isdigit(name[6])
&& ascii_isdigit(name[8])
&& ascii_isdigit(name[10])) {
- int major = atoi((char *)name + 6);
- int minor = atoi((char *)name + 8);
+ int major = atoi(name + 6);
+ int minor = atoi(name + 8);
// Expect "patch-9.9.01234".
n = (major < VIM_VERSION_MAJOR
|| (major == VIM_VERSION_MAJOR
&& (minor < VIM_VERSION_MINOR
|| (minor == VIM_VERSION_MINOR
- && has_patch(atoi((char *)name + 10))))));
+ && has_vim_patch(atoi(name + 10))))));
} else {
- n = has_patch(atoi((char *)name + 5));
+ n = has_vim_patch(atoi(name + 5));
+ }
+ } else if (STRNICMP(name, "nvim", 4) == 0) {
+ // Expect "nvim-x.y.z"
+ if (name[4] == '-' && strlen(name) >= 10) {
+ n = has_nvim_version(name + 5);
}
} else if (STRICMP(name, "vim_starting") == 0) {
n = (starting != 0);
} else if (STRICMP(name, "multi_byte_encoding") == 0) {
- n = has_mbyte;
+ n = has_mbyte != 0;
#if defined(USE_ICONV) && defined(DYNAMIC_ICONV)
} else if (STRICMP(name, "iconv") == 0) {
n = iconv_enabled(false);
@@ -10685,8 +10687,8 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
}
- if (n == FALSE && eval_has_provider((char *)name)) {
- n = TRUE;
+ if (!n && eval_has_provider(name)) {
+ n = true;
}
rettv->vval.v_number = n;
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index 6fd7603629..b49ae9da21 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -5537,7 +5537,7 @@ void ex_ownsyntax(exarg_T *eap)
}
}
-int syntax_present(win_T *win)
+bool syntax_present(win_T *win)
{
return win->w_s->b_syn_patterns.ga_len != 0
|| win->w_s->b_syn_clusters.ga_len != 0
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 2dfe5d3248..6b9c8bf6b1 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -2457,20 +2457,61 @@ static char *(extra_patches[]) = {
NULL
};
-/// Checks whether patch `n` has been included.
+/// Compares a version string to the current Nvim version.
///
-/// @param n The patch number.
+/// @param version Version string like "1.3.42"
///
-/// @return TRUE if patch "n" has been included.
-int has_patch(int n)
+/// @return true if Nvim is at or above the version.
+bool has_nvim_version(char *version_str)
+ FUNC_ATTR_NONNULL_ALL
{
- int i;
- for (i = 0; included_patches[i] != 0; ++i) {
+ char *p = version_str;
+ int major = 0;
+ int minor = 0;
+ int patch = 0;
+
+ if (!ascii_isdigit(*p)) {
+ return false;
+ }
+ major = atoi(p);
+ p = strchr(p, '.'); // Find the next dot.
+
+ if (p) {
+ p++; // Advance past the dot.
+ if (!ascii_isdigit(*p)) {
+ return false;
+ }
+ minor = atoi(p);
+ p = strchr(p, '.');
+ if (p) {
+ p++;
+ if (!ascii_isdigit(*p)) {
+ return false;
+ }
+ patch = atoi(p);
+ }
+ }
+
+ return (major < NVIM_VERSION_MAJOR
+ || (major == NVIM_VERSION_MAJOR
+ && (minor < NVIM_VERSION_MINOR
+ || (minor == NVIM_VERSION_MINOR
+ && patch <= NVIM_VERSION_PATCH))));
+}
+
+/// Checks whether a Vim patch has been included.
+///
+/// @param n Patch number.
+///
+/// @return true if patch `n` has been included.
+bool has_vim_patch(int n)
+{
+ for (int i = 0; included_patches[i] != 0; i++) {
if (included_patches[i] == n) {
- return TRUE;
+ return true;
}
}
- return FALSE;
+ return false;
}
void ex_version(exarg_T *eap)