summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt-pkg/packageset.cc35
-rw-r--r--apt-pkg/packageset.h4
2 files changed, 23 insertions, 16 deletions
diff --git a/apt-pkg/packageset.cc b/apt-pkg/packageset.cc
index baa1c211b..f296b7c45 100644
--- a/apt-pkg/packageset.cc
+++ b/apt-pkg/packageset.cc
@@ -22,20 +22,26 @@
/*}}}*/
namespace APT {
// FromRegEx - Return all packages in the cache matching a pattern /*{{{*/
-PackageSet PackageSet::FromRegEx(pkgCache &Cache, const char * const pattern, std::ostream &out) {
+PackageSet PackageSet::FromRegEx(pkgCache &Cache, std::string pattern, std::ostream &out) {
PackageSet pkgset;
+ std::string arch = "native";
+ static const char * const isregex = ".?+*|[^$";
- const char * I;
- for (I = pattern; *I != 0; I++)
- if (*I == '.' || *I == '?' || *I == '+' || *I == '*' ||
- *I == '|' || *I == '[' || *I == '^' || *I == '$')
- break;
- if (*I == 0)
+ if (pattern.find_first_of(isregex) == std::string::npos)
return pkgset;
+ size_t archfound = pattern.find_last_of(':');
+ if (archfound != std::string::npos) {
+ arch = pattern.substr(archfound+1);
+ if (arch.find_first_of(isregex) == std::string::npos)
+ pattern.erase(archfound);
+ else
+ arch = "native";
+ }
+
regex_t Pattern;
int Res;
- if ((Res = regcomp(&Pattern, pattern , REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0) {
+ if ((Res = regcomp(&Pattern, pattern.c_str() , REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0) {
char Error[300];
regerror(Res, &Pattern, Error, sizeof(Error));
_error->Error(_("Regex compilation error - %s"), Error);
@@ -46,19 +52,20 @@ PackageSet PackageSet::FromRegEx(pkgCache &Cache, const char * const pattern, st
{
if (regexec(&Pattern, Grp.Name(), 0, 0, 0) != 0)
continue;
- pkgCache::PkgIterator Pkg = Grp.FindPkg("native");
+ pkgCache::PkgIterator Pkg = Grp.FindPkg(arch);
if (Pkg.end() == true) {
- std::vector<std::string> archs = APT::Configuration::getArchitectures();
- for (std::vector<std::string>::const_iterator a = archs.begin();
- a != archs.end() || Pkg.end() != true; ++a) {
- Pkg = Grp.FindPkg(*a);
+ if (archfound == std::string::npos) {
+ std::vector<std::string> archs = APT::Configuration::getArchitectures();
+ for (std::vector<std::string>::const_iterator a = archs.begin();
+ a != archs.end() && Pkg.end() != true; ++a)
+ Pkg = Grp.FindPkg(*a);
}
if (Pkg.end() == true)
continue;
}
ioprintf(out, _("Note, selecting %s for regex '%s'\n"),
- Pkg.FullName(true).c_str(), pattern);
+ Pkg.FullName(true).c_str(), pattern.c_str());
pkgset.insert(Pkg);
}
diff --git a/apt-pkg/packageset.h b/apt-pkg/packageset.h
index 0bd60c56b..9f80d60ed 100644
--- a/apt-pkg/packageset.h
+++ b/apt-pkg/packageset.h
@@ -64,8 +64,8 @@ public: /*{{{*/
\param Cache the packages are in
\param pattern regular expression for package names
\param out stream to print the notice to */
- static APT::PackageSet FromRegEx(pkgCache &Cache, const char *pattern, std::ostream &out);
- static APT::PackageSet FromRegEx(pkgCache &Cache, const char *pattern) {
+ static APT::PackageSet FromRegEx(pkgCache &Cache, std::string pattern, std::ostream &out);
+ static APT::PackageSet FromRegEx(pkgCache &Cache, std::string const &pattern) {
std::ostream out (std::ofstream("/dev/null").rdbuf());
return APT::PackageSet::FromRegEx(Cache, pattern, out);
}