summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/apk_version.h3
-rw-r--r--src/app_vertest.c53
-rw-r--r--src/meson.build1
-rw-r--r--src/version.c34
4 files changed, 77 insertions, 14 deletions
diff --git a/src/apk_version.h b/src/apk_version.h
index ac6d50c..0996207 100644
--- a/src/apk_version.h
+++ b/src/apk_version.h
@@ -23,7 +23,8 @@
#define APK_DEPMASK_CHECKSUM (APK_VERSION_LESS|APK_VERSION_GREATER)
const char *apk_version_op_string(int result_mask);
-int apk_version_result_mask(const char *str);
+int apk_version_result_mask(const char *op);
+int apk_version_result_mask_blob(apk_blob_t op);
int apk_version_validate(apk_blob_t ver);
int apk_version_compare_blob_fuzzy(apk_blob_t a, apk_blob_t b, int fuzzy);
int apk_version_compare_blob(apk_blob_t a, apk_blob_t b);
diff --git a/src/app_vertest.c b/src/app_vertest.c
new file mode 100644
index 0000000..54d5f10
--- /dev/null
+++ b/src/app_vertest.c
@@ -0,0 +1,53 @@
+/* app_vertest.c - Alpine Package Keeper (APK)
+ *
+ * Copyright (C) 2005-2008 Natanael Copa <n@tanael.org>
+ * Copyright (C) 2008-2011 Timo Teräs <timo.teras@iki.fi>
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-only
+ */
+
+#include <stdio.h>
+#include "apk_defines.h"
+#include "apk_applet.h"
+#include "apk_database.h"
+#include "apk_version.h"
+#include "apk_print.h"
+
+static int vertest_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
+{
+ apk_blob_t arg, ver, op, space = APK_BLOB_STRLIT(" ");
+ char **parg;
+ int errors = 0;
+
+ foreach_array_item(parg, args) {
+ int ok = 0;
+
+ // arguments are either:
+ // "version" -> check validty
+ // "ver1 op ver2" -> check if that the comparison is true
+ arg = APK_BLOB_STR(*parg);
+ if (apk_blob_split(arg, space, &ver, &arg) &&
+ apk_blob_split(arg, space, &op, &arg)) {
+ if (apk_version_compare_blob(ver, arg) & apk_version_result_mask_blob(op))
+ ok = 1;
+ } else {
+ ok = apk_version_validate(arg);
+ }
+ if (!ok) {
+ if (apk_verbosity > 0)
+ printf("%s\n", *parg);
+ errors++;
+ }
+ }
+
+ return errors ? 1 : 0;
+}
+
+static struct apk_applet apk_vertest = {
+ .open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE | APK_OPENF_NO_REPOS,
+ .name = "vertest",
+ .main = vertest_main,
+};
+
+APK_DEFINE_APPLET(apk_vertest);
diff --git a/src/meson.build b/src/meson.build
index 216ce0e..f2b8cc9 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -62,6 +62,7 @@ apk_src = [
'app_stats.c',
'app_verify.c',
'app_version.c',
+ 'app_vertest.c',
'help.c',
]
diff --git a/src/version.c b/src/version.c
index f6fc5af..7c1c0b4 100644
--- a/src/version.c
+++ b/src/version.c
@@ -161,24 +161,32 @@ const char *apk_version_op_string(int mask)
}
}
-int apk_version_result_mask(const char *str)
+int apk_version_result_mask_blob(apk_blob_t op)
{
- int r = 0;
- switch (*str) {
- case '<':
- r = APK_VERSION_LESS;
- str++;
- break;
- case '>':
- r = APK_VERSION_GREATER;
- str++;
- break;
+ int i, r = 0;
+ for (i = 0; i < op.len; i++) {
+ switch (op.ptr[i]) {
+ case '<':
+ r |= APK_VERSION_LESS;
+ break;
+ case '>':
+ r |= APK_VERSION_GREATER;
+ break;
+ case '=':
+ r |= APK_VERSION_EQUAL;
+ break;
+ default:
+ return 0;
+ }
}
- if (*str == '=')
- r |= APK_VERSION_EQUAL;
return r;
}
+int apk_version_result_mask(const char *op)
+{
+ return apk_version_result_mask_blob(APK_BLOB_STR(op));
+}
+
int apk_version_validate(apk_blob_t ver)
{
int t = TOKEN_DIGIT;