diff --git a/3RDPARTY b/3RDPARTY index 96dd6811..a483348e 100644 --- a/3RDPARTY +++ b/3RDPARTY @@ -3,8 +3,8 @@ internal use in the code: - queue.h from NetBSD: include/queue.h. -- package pattern matching code from NetBSD: - lib/external/dewey.c and lib/external/match.c +- relational dewey version matching code from NetBSD: + lib/external/dewey.c - strlcat and strlcpy functions from OpenBSD: lib/compat/strlc{at,cpy}.c diff --git a/lib/Makefile b/lib/Makefile index 86335fb5..f98966c0 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -38,7 +38,7 @@ endif # External code used by libxbps EXTOBJS = external/dewey.o external/fexec.o external/humanize_number.o -EXTOBJS += external/match.o external/mkpath.o +EXTOBJS += external/mkpath.o # libxbps OBJS = package_configure.o package_config_files.o package_orphans.o diff --git a/lib/external/match.c b/lib/external/match.c deleted file mode 100644 index dc7890ab..00000000 --- a/lib/external/match.c +++ /dev/null @@ -1,98 +0,0 @@ -/* $NetBSD: opattern.c,v 1.5 2009/02/02 12:35:01 joerg Exp $ */ - -/* - * FreeBSD install - a package for the installation and maintainance - * of non-core utilities. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Jordan K. Hubbard - * 18 July 1993 - * - * Miscellaneous string utilities. - * - */ - -#include -#include -#include -#include -#include -#include - -#include "xbps_api_impl.h" - -/* - * Perform glob match on "pkg" against "pattern". - * Return 1 on match, 0 otherwise. - */ -static int -glob_match(const char *pattern, const char *pkg) -{ - return fnmatch(pattern, pkg, FNM_PERIOD) == 0; -} - -/* - * Perform simple match on "pkg" against "pattern". - * Return 1 on match, 0 otherwise. - */ -static int -simple_match(const char *pattern, const char *pkg) -{ - return strcmp(pattern, pkg) == 0; -} - -/* - * Performs a fast check if pattern can ever match pkg. - * Returns 1 if a match is possible and 0 otherwise. - */ -static int -quick_pkg_match(const char *pattern, const char *pkg) -{ -#define simple(x) (isalnum((unsigned char)(x)) || (x) == '-') - if (!simple(pattern[0])) - return 1; - if (pattern[0] != pkg[0]) - return 0; - - if (!simple(pattern[1])) - return 1; - if (pattern[1] != pkg[1]) - return 0; - return 1; -#undef simple -} - -/* - * Match pkg against pattern, return 1 if matching, 0 otherwise or -1 on error. - */ -int -xbps_pkgpattern_match(const char *pkg, const char *pattern) -{ - if (!quick_pkg_match(pattern, pkg)) - return 0; - - if (strpbrk(pattern, "<>") != NULL) { - /* perform relational dewey match on version number */ - return dewey_match(pattern, pkg); - } - if (strpbrk(pattern, "*?[]") != NULL) { - /* glob match */ - if (glob_match(pattern, pkg)) - return 1; - } - - /* no dewey or glob match -> simple compare */ - if (simple_match(pattern, pkg)) - return 1; - - /* no match */ - return 0; -} diff --git a/lib/util.c b/lib/util.c index 9b2d2fc5..a7c6b126 100644 --- a/lib/util.c +++ b/lib/util.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #ifdef HAVE_CONFIG_H #include "config.h" @@ -304,3 +304,26 @@ xbps_xasprintf(const char *fmt, ...) return buf; } + +/* + * Match pkg against pattern, return 1 if matching, 0 otherwise or -1 on error. + */ +int +xbps_pkgpattern_match(const char *pkg, const char *pattern) +{ + /* simple match on "pkg" against "pattern */ + if (strcmp(pattern, pkg) == 0) + return 1; + + /* perform relational dewey match on version number */ + if (strpbrk(pattern, "<>") != NULL) + return dewey_match(pattern, pkg); + + /* glob match */ + if (strpbrk(pattern, "*?[]") != NULL) + if (fnmatch(pattern, pkg, FNM_PERIOD) == 0) + return 1; + + /* no match */ + return 0; +}