+ if (Pkg.end() == true)
+ return helper.canNotFindPkgName(Cache, str);
+ return Pkg;
+}
+ /*}}}*/
+// FromGroup - Returns the package defined by this string /*{{{*/
+bool PackageContainerInterface::FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache,
+ std::string pkg, CacheSetHelper &helper) {
+ if (unlikely(Cache.GetPkgCache() == 0))
+ return false;
+
+ size_t const archfound = pkg.find_last_of(':');
+ std::string arch;
+ if (archfound != std::string::npos) {
+ arch = pkg.substr(archfound+1);
+ pkg.erase(archfound);
+ if (arch == "all" || arch == "native")
+ arch = _config->Find("APT::Architecture");
+ }
+
+ pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(pkg);
+ if (Grp.end() == false) {
+ if (arch.empty() == true) {
+ pkgCache::PkgIterator Pkg = Grp.FindPreferredPkg();
+ if (Pkg.end() == false)
+ {
+ pci->insert(Pkg);
+ return true;
+ }
+ } else {
+ bool found = false;
+ // for 'linux-any' return the first package matching, for 'linux-*' return all matches
+ bool const isGlobal = arch.find('*') != std::string::npos;
+ APT::CacheFilter::PackageArchitectureMatchesSpecification pams(arch);
+ for (pkgCache::PkgIterator Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg)) {
+ if (pams(Pkg) == false)
+ continue;
+ pci->insert(Pkg);
+ found = true;
+ if (isGlobal == false)
+ break;
+ }
+ if (found == true)
+ return true;
+ }
+ }
+
+ pkgCache::PkgIterator Pkg = helper.canNotFindPkgName(Cache, pkg);
+ if (Pkg.end() == true)
+ return false;
+
+ pci->insert(Pkg);
+ return true;
+}
+ /*}}}*/
+// FromString - Return all packages matching a specific string /*{{{*/
+bool PackageContainerInterface::FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str, CacheSetHelper &helper) {
+ bool found = true;
+ _error->PushToStack();
+
+ if (FromGroup(pci, Cache, str, helper) == false &&
+ FromTask(pci, Cache, str, helper) == false &&
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+ FromFnmatch(pci, Cache, str, helper) == false)
+#endif
+ FromRegEx(pci, Cache, str, helper) == false)
+ {
+ helper.canNotFindPackage(pci, Cache, str);
+ found = false;
+ }
+
+ if (found == true)
+ _error->RevertToStack();
+ else
+ _error->MergeWithStack();
+ return found;
+}
+ /*}}}*/
+// FromCommandLine - Return all packages specified on commandline /*{{{*/
+bool PackageContainerInterface::FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) {
+ bool found = false;
+ for (const char **I = cmdline; *I != 0; ++I)
+ found |= PackageContainerInterface::FromString(pci, Cache, *I, helper);
+ return found;
+}
+ /*}}}*/
+// FromModifierCommandLine - helper doing the work for PKG:GroupedFromCommandLine /*{{{*/
+bool PackageContainerInterface::FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
+ pkgCacheFile &Cache, const char * cmdline,
+ std::list<Modifier> const &mods, CacheSetHelper &helper) {
+ std::string str = cmdline;
+ unsigned short fallback = modID;
+ bool modifierPresent = false;
+ for (std::list<Modifier>::const_iterator mod = mods.begin();
+ mod != mods.end(); ++mod) {
+ size_t const alength = strlen(mod->Alias);
+ switch(mod->Pos) {
+ case Modifier::POSTFIX:
+ if (str.compare(str.length() - alength, alength,
+ mod->Alias, 0, alength) != 0)
+ continue;
+ str.erase(str.length() - alength);
+ modID = mod->ID;
+ break;
+ case Modifier::PREFIX:
+ continue;
+ case Modifier::NONE:
+ continue;
+ }
+ modifierPresent = true;
+ break;
+ }
+ if (modifierPresent == true) {
+ bool const errors = helper.showErrors(false);
+ pkgCache::PkgIterator Pkg = FromName(Cache, cmdline, helper);
+ helper.showErrors(errors);
+ if (Pkg.end() == false) {
+ pci->insert(Pkg);
+ modID = fallback;
+ return true;
+ }
+ }
+ return FromString(pci, Cache, str, helper);
+}
+ /*}}}*/
+// FromModifierCommandLine - helper doing the work for VER:GroupedFromCommandLine /*{{{*/
+bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID,
+ VersionContainerInterface * const vci,
+ pkgCacheFile &Cache, const char * cmdline,
+ std::list<Modifier> const &mods,
+ CacheSetHelper &helper) {
+ Version select = NEWEST;
+ std::string str = cmdline;
+ if (unlikely(str.empty() == true))
+ return false;
+ bool modifierPresent = false;
+ unsigned short fallback = modID;
+ for (std::list<Modifier>::const_iterator mod = mods.begin();
+ mod != mods.end(); ++mod) {
+ if (modID == fallback && mod->ID == fallback)
+ select = mod->SelectVersion;
+ size_t const alength = strlen(mod->Alias);
+ switch(mod->Pos) {
+ case Modifier::POSTFIX:
+ if (str.length() <= alength ||
+ str.compare(str.length() - alength, alength, mod->Alias, 0, alength) != 0)
+ continue;
+ str.erase(str.length() - alength);
+ modID = mod->ID;
+ select = mod->SelectVersion;
+ break;
+ case Modifier::PREFIX:
+ continue;
+ case Modifier::NONE:
+ continue;
+ }
+ modifierPresent = true;
+ break;
+ }
+ if (modifierPresent == true) {
+ bool const errors = helper.showErrors(false);
+ bool const found = VersionContainerInterface::FromString(vci, Cache, cmdline, select, helper, true);
+ helper.showErrors(errors);
+ if (found == true) {
+ modID = fallback;
+ return true;
+ }