aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/version.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/version.c')
-rw-r--r--src/nvim/version.c85
1 files changed, 71 insertions, 14 deletions
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 153b7fb5fd..a215001194 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -7,6 +7,7 @@
#include <assert.h>
#include <limits.h>
+#include "nvim/api/private/helpers.h"
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/iconv.h"
@@ -129,10 +130,10 @@ static int included_patches[] = {
// 2315,
// 2314,
// 2313,
- // 2312,
+ 2312,
// 2311,
// 2310 NA
- // 2309,
+ 2309,
// 2308 NA
// 2307,
// 2306,
@@ -204,7 +205,7 @@ static int included_patches[] = {
// 2240,
// 2239,
// 2238 NA
- // 2237,
+ 2237,
// 2236,
// 2235,
// 2234 NA
@@ -229,7 +230,7 @@ static int included_patches[] = {
// 2215,
// 2214 NA
2213,
- // 2212,
+ 2212,
// 2211 NA
// 2210 NA
// 2209,
@@ -313,7 +314,7 @@ static int included_patches[] = {
// 2131 NA
// 2130 NA
// 2129 NA
- // 2128,
+ 2128,
// 2127,
// 2126,
// 2125,
@@ -332,7 +333,7 @@ static int included_patches[] = {
2112,
// 2111,
// 2110,
- // 2109,
+ 2109,
// 2108 NA
// 2107,
// 2106,
@@ -2457,20 +2458,72 @@ 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;
+}
+
+Dictionary version_dict(void) {
+ Dictionary d = ARRAY_DICT_INIT;
+ PUT(d, "major", INTEGER_OBJ(NVIM_VERSION_MAJOR));
+ PUT(d, "minor", INTEGER_OBJ(NVIM_VERSION_MINOR));
+ PUT(d, "patch", INTEGER_OBJ(NVIM_VERSION_PATCH));
+ PUT(d, "api_level", INTEGER_OBJ(NVIM_API_LEVEL));
+ PUT(d, "api_compatible", INTEGER_OBJ(NVIM_API_LEVEL_COMPAT));
+ PUT(d, "api_prerelease", BOOLEAN_OBJ(NVIM_API_PRERELEASE));
+ return d;
}
void ex_version(exarg_T *eap)
@@ -2529,7 +2582,11 @@ static void list_features(void)
}
} else {
while (msg_col % width) {
+ int old_msg_col = msg_col;
msg_putchar(' ');
+ if (old_msg_col == msg_col) {
+ break; // XXX: Avoid infinite loop.
+ }
}
}
} else {