libxbps: move xbps_pkgpattern_match to util.c and simplify.

This commit is contained in:
Juan RP
2012-05-30 22:38:35 +02:00
parent 27aacf97f4
commit 1bfb1ae028
4 changed files with 27 additions and 102 deletions

View File

@@ -33,7 +33,7 @@
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <fnmatch.h>
#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;
}