From b917917067e757c4479a344a263ef7cf43c00866 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 12 Aug 2013 23:24:08 +0200 Subject: squash merge of the feature/apt-binary branch without the changes from experimental --- apt-private/private-list.cc | 158 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 apt-private/private-list.cc (limited to 'apt-private/private-list.cc') diff --git a/apt-private/private-list.cc b/apt-private/private-list.cc new file mode 100644 index 000000000..ac72ce51a --- /dev/null +++ b/apt-private/private-list.cc @@ -0,0 +1,158 @@ +// Include Files /*{{{*/ +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "private-cmndline.h" +#include "private-list.h" +#include "private-output.h" +#include "private-cacheset.h" + +#include + /*}}}*/ + +struct PackageSortAlphabetic +{ + bool operator () (const pkgCache::PkgIterator &p_lhs, + const pkgCache::PkgIterator &p_rhs) + { + const std::string &l_name = p_lhs.FullName(true); + const std::string &r_name = p_rhs.FullName(true); + return (l_name < r_name); + } +}; + +class PackageNameMatcher : public Matcher +{ + public: + PackageNameMatcher(const char **patterns) + { + for(int i=0; patterns[i] != NULL; i++) + { + std::string pattern = patterns[i]; + APT::CacheFilter::PackageMatcher *cachefilter = NULL; + if(_config->FindB("APT::Cmd::UseRegexp", false) == true) + cachefilter = new APT::CacheFilter::PackageNameMatchesRegEx(pattern); + else + cachefilter = new APT::CacheFilter::PackageNameMatchesFnmatch(pattern); + filters.push_back(cachefilter); + } + } + virtual ~PackageNameMatcher() + { + for(J=filters.begin(); J != filters.end(); J++) + delete *J; + } + virtual bool operator () (const pkgCache::PkgIterator &P) + { + for(J=filters.begin(); J != filters.end(); J++) + { + APT::CacheFilter::PackageMatcher *cachefilter = *J; + if((*cachefilter)(P)) + return true; + } + return false; + } + +private: + std::vector filters; + std::vector::const_iterator J; +}; + + +void ListAllVersions(pkgCacheFile &CacheFile, pkgRecords &records, + pkgCache::PkgIterator P, + std::ostream &outs) +{ + for (pkgCache::VerIterator Ver = P.VersionList(); + Ver.end() == false; Ver++) + ListSingleVersion(CacheFile, records, Ver, outs); +} + +// list - list package based on criteria /*{{{*/ +// --------------------------------------------------------------------- +bool List(CommandLine &Cmd) +{ + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + pkgRecords records(CacheFile); + + if (unlikely(Cache == NULL)) + return false; + + const char **patterns; + const char *all_pattern[] = { "*", NULL}; + + if (strv_length(Cmd.FileList + 1) == 0) + { + patterns = all_pattern; + } else { + patterns = Cmd.FileList + 1; + } + + std::map output_map; + std::map::const_iterator K; + + PackageNameMatcher matcher(patterns); + LocalitySortedVersionSet bag; + OpTextProgress progress; + progress.OverallProgress(0, + Cache->Head().PackageCount, + Cache->Head().PackageCount, + _("Listing")); + GetLocalitySortedVersionSet(CacheFile, bag, matcher, progress); + for (LocalitySortedVersionSet::iterator V = bag.begin(); V != bag.end(); V++) + { + std::stringstream outs; + if(_config->FindB("APT::Cmd::AllVersions", false) == true) + { + ListAllVersions(CacheFile, records, V.ParentPkg(), outs); + output_map.insert(std::make_pair( + V.ParentPkg().Name(), outs.str())); + } else { + ListSingleVersion(CacheFile, records, V, outs); + output_map.insert(std::make_pair( + V.ParentPkg().Name(), outs.str())); + } + } + + // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status) + // output the sorted map + for (K = output_map.begin(); K != output_map.end(); K++) + std::cout << (*K).second << std::endl; + + + return true; +} + -- cgit v1.2.3