]>
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/strutl.h>
22 namespace CacheFilter
{
23 PackageNameMatchesRegEx::PackageNameMatchesRegEx(std::string
const &Pattern
) : d(NULL
) {/*{{{*/
24 pattern
= new regex_t
;
25 int const Res
= regcomp(pattern
, Pattern
.c_str(), REG_EXTENDED
| REG_ICASE
| REG_NOSUB
);
32 regerror(Res
, pattern
, Error
, sizeof(Error
));
33 _error
->Error(_("Regex compilation error - %s"), Error
);
36 bool PackageNameMatchesRegEx::operator() (pkgCache::PkgIterator
const &Pkg
) {/*{{{*/
37 if (unlikely(pattern
== NULL
))
40 return regexec(pattern
, Pkg
.Name(), 0, 0, 0) == 0;
43 bool PackageNameMatchesRegEx::operator() (pkgCache::GrpIterator
const &Grp
) {/*{{{*/
44 if (unlikely(pattern
== NULL
))
47 return regexec(pattern
, Grp
.Name(), 0, 0, 0) == 0;
50 PackageNameMatchesRegEx::~PackageNameMatchesRegEx() { /*{{{*/
58 // CompleteArch to <kernel>-<cpu> tuple /*{{{*/
59 //----------------------------------------------------------------------
60 /* The complete architecture, consisting of <kernel>-<cpu>. */
61 static std::string
CompleteArch(std::string
const &arch
) {
62 if (arch
.find('-') != std::string::npos
) {
63 // ensure that only -any- is replaced and not something like company-
64 std::string complete
= std::string("-").append(arch
).append("-");
65 complete
= SubstVar(complete
, "-any-", "-*-");
66 complete
= complete
.substr(1, complete
.size()-2);
69 else if (arch
== "armel") return "linux-arm";
70 else if (arch
== "armhf") return "linux-arm";
71 else if (arch
== "lpia") return "linux-i386";
72 else if (arch
== "powerpcspe") return "linux-powerpc";
73 else if (arch
== "uclibc-linux-armel") return "linux-arm";
74 else if (arch
== "uclinux-armel") return "uclinux-arm";
75 else if (arch
== "any") return "*-*";
76 else return "linux-" + arch
;
79 PackageArchitectureMatchesSpecification::PackageArchitectureMatchesSpecification(std::string
const &pattern
, bool const isPattern
) :/*{{{*/
80 literal(pattern
), isPattern(isPattern
), d(NULL
) {
81 complete
= CompleteArch(pattern
);
84 bool PackageArchitectureMatchesSpecification::operator() (char const * const &arch
) {/*{{{*/
85 if (strcmp(literal
.c_str(), arch
) == 0 ||
86 strcmp(complete
.c_str(), arch
) == 0)
88 std::string
const pkgarch
= CompleteArch(arch
);
89 if (isPattern
== true)
90 return fnmatch(complete
.c_str(), pkgarch
.c_str(), 0) == 0;
91 return fnmatch(pkgarch
.c_str(), complete
.c_str(), 0) == 0;
94 bool PackageArchitectureMatchesSpecification::operator() (pkgCache::PkgIterator
const &Pkg
) {/*{{{*/
95 return (*this)(Pkg
.Arch());
98 bool PackageArchitectureMatchesSpecification::operator() (pkgCache::VerIterator
const &Ver
) {/*{{{*/
99 return (*this)(Ver
.ParentPkg());
102 PackageArchitectureMatchesSpecification::~PackageArchitectureMatchesSpecification() { /*{{{*/