]>
git.saurik.com Git - apt.git/blob - apt-pkg/cachefilter.cc
1 // -*- mode: cpp; mode: fold -*-
3 /** \file cachefilter.h
4 Collection of functor classes */
6 // Include Files /*{{{*/
9 #include <apt-pkg/cachefilter.h>
10 #include <apt-pkg/error.h>
11 #include <apt-pkg/pkgcache.h>
12 #include <apt-pkg/cacheiterators.h>
13 #include <apt-pkg/strutl.h>
14 #include <apt-pkg/macros.h>
24 namespace CacheFilter
{
25 PackageNameMatchesRegEx::PackageNameMatchesRegEx(std::string
const &Pattern
) : d(NULL
) {/*{{{*/
26 pattern
= new regex_t
;
27 int const Res
= regcomp(pattern
, Pattern
.c_str(), REG_EXTENDED
| REG_ICASE
| REG_NOSUB
);
34 regerror(Res
, pattern
, Error
, sizeof(Error
));
35 _error
->Error(_("Regex compilation error - %s"), Error
);
38 bool PackageNameMatchesRegEx::operator() (pkgCache::PkgIterator
const &Pkg
) {/*{{{*/
39 if (unlikely(pattern
== NULL
))
42 return regexec(pattern
, Pkg
.Name(), 0, 0, 0) == 0;
45 bool PackageNameMatchesRegEx::operator() (pkgCache::GrpIterator
const &Grp
) {/*{{{*/
46 if (unlikely(pattern
== NULL
))
49 return regexec(pattern
, Grp
.Name(), 0, 0, 0) == 0;
52 PackageNameMatchesRegEx::~PackageNameMatchesRegEx() { /*{{{*/
60 // Fnmatch support /*{{{*/
61 //----------------------------------------------------------------------
62 bool PackageNameMatchesFnmatch::operator() (pkgCache::PkgIterator
const &Pkg
) {/*{{{*/
63 return fnmatch(Pattern
.c_str(), Pkg
.Name(), FNM_CASEFOLD
) == 0;
66 bool PackageNameMatchesFnmatch::operator() (pkgCache::GrpIterator
const &Grp
) {/*{{{*/
67 return fnmatch(Pattern
.c_str(), Grp
.Name(), FNM_CASEFOLD
) == 0;
71 // CompleteArch to <kernel>-<cpu> tuple /*{{{*/
72 //----------------------------------------------------------------------
73 /* The complete architecture, consisting of <kernel>-<cpu>. */
74 static std::string
CompleteArch(std::string
const &arch
) {
75 if (arch
.find('-') != std::string::npos
) {
76 // ensure that only -any- is replaced and not something like company-
77 std::string complete
= std::string("-").append(arch
).append("-");
78 complete
= SubstVar(complete
, "-any-", "-*-");
79 complete
= complete
.substr(1, complete
.size()-2);
82 else if (arch
== "any") return "*-*";
83 else return "linux-" + arch
;
86 PackageArchitectureMatchesSpecification::PackageArchitectureMatchesSpecification(std::string
const &pattern
, bool const isPattern
) :/*{{{*/
87 literal(pattern
), complete(CompleteArch(pattern
)), isPattern(isPattern
), d(NULL
) {
90 bool PackageArchitectureMatchesSpecification::operator() (char const * const &arch
) {/*{{{*/
91 if (strcmp(literal
.c_str(), arch
) == 0 ||
92 strcmp(complete
.c_str(), arch
) == 0)
94 std::string
const pkgarch
= CompleteArch(arch
);
95 if (isPattern
== true)
96 return fnmatch(complete
.c_str(), pkgarch
.c_str(), 0) == 0;
97 return fnmatch(pkgarch
.c_str(), complete
.c_str(), 0) == 0;
100 bool PackageArchitectureMatchesSpecification::operator() (pkgCache::PkgIterator
const &Pkg
) {/*{{{*/
101 return (*this)(Pkg
.Arch());
104 bool PackageArchitectureMatchesSpecification::operator() (pkgCache::VerIterator
const &Ver
) {/*{{{*/
105 return (*this)(Ver
.ParentPkg());
108 PackageArchitectureMatchesSpecification::~PackageArchitectureMatchesSpecification() { /*{{{*/