From d5ddeb401b33ea3dc7d8db60665dda33c541eec0 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 7 May 2012 03:26:17 -0500 Subject: [PATCH] main: add --max-version and --exact version (issue #8) --- main.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/main.c b/main.c index 405c9a3..d38d90a 100644 --- a/main.c +++ b/main.c @@ -60,6 +60,8 @@ static int want_keep_system_libs = 0; static int maximum_traverse_depth = -1; static char *required_pkgconfig_version = NULL; +static char *required_exact_module_version = NULL; +static char *required_max_module_version = NULL; static char *required_module_version = NULL; static char *want_variable = NULL; @@ -508,6 +510,8 @@ main(int argc, char *argv[]) { "keep-system-cflags", no_argument, &want_keep_system_cflags, 26, }, { "keep-system-libs", no_argument, &want_keep_system_libs, 26, }, { "define-variable", required_argument, NULL, 27, }, + { "exact-version", required_argument, NULL, 28, }, + { "max-version", required_argument, NULL, 29, }, { NULL, 0, NULL, 0 } }; @@ -530,6 +534,12 @@ main(int argc, char *argv[]) case 27: pkg_tuple_define_global(optarg); break; + case 28: + required_exact_module_version = optarg; + break; + case 29: + required_max_module_version = optarg; + break; default: break; } @@ -589,6 +599,44 @@ main(int argc, char *argv[]) return EXIT_FAILURE; } + if (required_exact_module_version != NULL) + { + pkg_t *pkg; + const char *package; + + package = argv[optind]; + if (package == NULL) + return EXIT_SUCCESS; + + pkg = pkg_find(package, global_traverse_flags); + if (pkg == NULL) + return EXIT_FAILURE; + + if (pkg_compare_version(pkg->version, required_exact_module_version) == 0) + return EXIT_SUCCESS; + + return EXIT_FAILURE; + } + + if (required_max_module_version != NULL) + { + pkg_t *pkg; + const char *package; + + package = argv[optind]; + if (package == NULL) + return EXIT_SUCCESS; + + pkg = pkg_find(package, global_traverse_flags); + if (pkg == NULL) + return EXIT_FAILURE; + + if (pkg_compare_version(pkg->version, required_max_module_version) <= 0) + return EXIT_SUCCESS; + + return EXIT_FAILURE; + } + while (1) { const char *package = argv[optind];