X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/304731b8f23e03d15d1c2d6f66e1bf5f26ac0ca2..c511c5e8ed3f59ddee1b174b39e5cc16a2f11922:/apt-private/private-list.cc diff --git a/apt-private/private-list.cc b/apt-private/private-list.cc index bbf4607f9..aa3a2c24b 100644 --- a/apt-private/private-list.cc +++ b/apt-private/private-list.cc @@ -1,48 +1,33 @@ // 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 +#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 #include /*}}}*/ -struct PackageSortAlphabetic +struct PackageSortAlphabetic /*{{{*/ { bool operator () (const pkgCache::PkgIterator &p_lhs, const pkgCache::PkgIterator &p_rhs) @@ -58,11 +43,11 @@ class PackageNameMatcher : public Matcher public: PackageNameMatcher(const char **patterns) { - for(int i=0; patterns[i] != NULL; i++) + 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) + if(_config->FindB("APT::Cmd::Use-Regexp", false) == true) cachefilter = new APT::CacheFilter::PackageNameMatchesRegEx(pattern); else cachefilter = new APT::CacheFilter::PackageNameMatchesFnmatch(pattern); @@ -71,12 +56,12 @@ class PackageNameMatcher : public Matcher } virtual ~PackageNameMatcher() { - for(J=filters.begin(); J != filters.end(); J++) + 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++) + for(J=filters.begin(); J != filters.end(); ++J) { APT::CacheFilter::PackageMatcher *cachefilter = *J; if((*cachefilter)(P)) @@ -90,27 +75,28 @@ private: std::vector::const_iterator J; #undef PackageMatcher }; - - -void ListAllVersions(pkgCacheFile &CacheFile, pkgRecords &records, - pkgCache::PkgIterator P, - std::ostream &outs) + /*}}}*/ +static void ListAllVersions(pkgCacheFile &CacheFile, pkgRecords &records,/*{{{*/ + pkgCache::PkgIterator const &P, std::ostream &outs, + std::string const &format) { for (pkgCache::VerIterator Ver = P.VersionList(); - Ver.end() == false; Ver++) - ListSingleVersion(CacheFile, records, Ver, outs); + Ver.end() == false; ++Ver) + { + ListSingleVersion(CacheFile, records, Ver, outs, format); + outs << std::endl; + } } - + /*}}}*/ // list - list package based on criteria /*{{{*/ // --------------------------------------------------------------------- -bool List(CommandLine &Cmd) +bool DoList(CommandLine &Cmd) { pkgCacheFile CacheFile; pkgCache *Cache = CacheFile.GetPkgCache(); - pkgRecords records(CacheFile); - if (unlikely(Cache == NULL)) return false; + pkgRecords records(CacheFile); const char **patterns; const char *all_pattern[] = { "*", NULL}; @@ -122,37 +108,48 @@ bool List(CommandLine &Cmd) patterns = Cmd.FileList + 1; } - std::map output_map; - std::map::const_iterator K; + std::string format = "${color:highlight}${Package}${color:neutral}/${Origin} ${Version} ${Architecture}${ }${apt:Status}"; + if (_config->FindB("APT::Cmd::List-Include-Summary", false) == true) + format += "\n ${Description}\n"; PackageNameMatcher matcher(patterns); LocalitySortedVersionSet bag; - OpTextProgress progress; + OpTextProgress progress(*_config); 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++) + GetLocalitySortedVersionSet(CacheFile, &bag, matcher, &progress); + bool const ShowAllVersions = _config->FindB("APT::Cmd::All-Versions", false); + std::map output_map; + 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())); - } + if(ShowAllVersions == true) + ListAllVersions(CacheFile, records, V.ParentPkg(), outs, format); + else + ListSingleVersion(CacheFile, records, V, outs, format); + 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::map::const_iterator K; + for (K = output_map.begin(); K != output_map.end(); ++K) std::cout << (*K).second << std::endl; + // be nice and tell the user if there is more to see + if (bag.size() == 1 && ShowAllVersions == false) + { + // start with -1 as we already displayed one version + int versions = -1; + pkgCache::VerIterator Ver = *bag.begin(); + for ( ; Ver.end() == false; ++Ver) + ++versions; + if (versions > 0) + _error->Notice(P_("There is %i additional version. Please use the '-a' switch to see it", "There are %i additional versions. Please use the '-a' switch to see them.", versions), versions); + } return true; }