]> git.saurik.com Git - apt.git/blobdiff - apt-private/private-list.cc
Merge remote-tracking branch 'upstream/debian/sid' into debian/sid
[apt.git] / apt-private / private-list.cc
index ac72ce51a6c7013bdc9783ee3cee4ea471fdb3f1..b69002103e3d44d8e3a6b33315fb6a48dc3f3874 100644 (file)
@@ -1,48 +1,33 @@
 // Include Files                                                       /*{{{*/
 #include <config.h>
 
 // Include Files                                                       /*{{{*/
 #include <config.h>
 
-#include <apt-pkg/error.h>
 #include <apt-pkg/cachefile.h>
 #include <apt-pkg/cachefilter.h>
 #include <apt-pkg/cacheset.h>
 #include <apt-pkg/cachefile.h>
 #include <apt-pkg/cachefilter.h>
 #include <apt-pkg/cacheset.h>
-#include <apt-pkg/init.h>
-#include <apt-pkg/progress.h>
-#include <apt-pkg/sourcelist.h>
 #include <apt-pkg/cmndline.h>
 #include <apt-pkg/cmndline.h>
-#include <apt-pkg/strutl.h>
-#include <apt-pkg/fileutl.h>
 #include <apt-pkg/pkgrecords.h>
 #include <apt-pkg/pkgrecords.h>
-#include <apt-pkg/srcrecords.h>
-#include <apt-pkg/version.h>
-#include <apt-pkg/policy.h>
-#include <apt-pkg/tagfile.h>
-#include <apt-pkg/algorithms.h>
-#include <apt-pkg/sptr.h>
-#include <apt-pkg/pkgsystem.h>
-#include <apt-pkg/indexfile.h>
-#include <apt-pkg/metaindex.h>
+#include <apt-pkg/progress.h>
+#include <apt-pkg/strutl.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/macros.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
 
 
+#include <apt-private/private-cacheset.h>
+#include <apt-private/private-list.h>
+#include <apt-private/private-output.h>
+
+#include <iostream>
 #include <sstream>
 #include <sstream>
-#include <vector>
+#include <map>
+#include <string>
 #include <utility>
 #include <utility>
-#include <cassert>
-#include <locale.h>
-#include <iostream>
-#include <unistd.h>
-#include <errno.h>
-#include <regex.h>
-#include <stdio.h>
-#include <algorithm>
-
-#include "private-cmndline.h"
-#include "private-list.h"
-#include "private-output.h"
-#include "private-cacheset.h"
+#include <vector>
 
 #include <apti18n.h>
                                                                        /*}}}*/
 
 
 #include <apti18n.h>
                                                                        /*}}}*/
 
-struct PackageSortAlphabetic
+struct PackageSortAlphabetic                                           /*{{{*/
 {
    bool operator () (const pkgCache::PkgIterator &p_lhs, 
                      const pkgCache::PkgIterator &p_rhs)
 {
    bool operator () (const pkgCache::PkgIterator &p_lhs, 
                      const pkgCache::PkgIterator &p_rhs)
@@ -52,31 +37,39 @@ struct PackageSortAlphabetic
        return (l_name < r_name);
     }
 };
        return (l_name < r_name);
     }
 };
-
-class PackageNameMatcher : public Matcher
+                                                                       /*}}}*/
+class PackageNameMatcher : public Matcher                              /*{{{*/
 {
 {
+#ifdef PACKAGE_MATCHER_ABI_COMPAT
+#define PackageMatcher PackageNameMatchesFnmatch
+#endif
   public:
    PackageNameMatcher(const char **patterns)
    {
   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];
       {
          std::string pattern = patterns[i];
+#ifdef PACKAGE_MATCHER_ABI_COMPAT
+            APT::CacheFilter::PackageNameMatchesFnmatch *cachefilter = NULL;
+            cachefilter = new APT::CacheFilter::PackageNameMatchesFnmatch(pattern);
+#else
          APT::CacheFilter::PackageMatcher *cachefilter = NULL;
          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);
             cachefilter = new APT::CacheFilter::PackageNameMatchesRegEx(pattern);
          else
             cachefilter = new APT::CacheFilter::PackageNameMatchesFnmatch(pattern);
+#endif
          filters.push_back(cachefilter);
       }
    }
    virtual ~PackageNameMatcher()
    {
          filters.push_back(cachefilter);
       }
    }
    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) 
    {
          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)) 
       {
          APT::CacheFilter::PackageMatcher *cachefilter = *J;
          if((*cachefilter)(P)) 
@@ -88,28 +81,31 @@ class PackageNameMatcher : public Matcher
 private:
    std::vector<APT::CacheFilter::PackageMatcher*> filters;   
    std::vector<APT::CacheFilter::PackageMatcher*>::const_iterator J;
 private:
    std::vector<APT::CacheFilter::PackageMatcher*> filters;   
    std::vector<APT::CacheFilter::PackageMatcher*>::const_iterator J;
+   #undef PackageMatcher
 };
 };
-
-
-void ListAllVersions(pkgCacheFile &CacheFile, pkgRecords &records, 
+                                                                       /*}}}*/
+static void ListAllVersions(pkgCacheFile &CacheFile, pkgRecords &records,/*{{{*/
                      pkgCache::PkgIterator P,    
                      pkgCache::PkgIterator P,    
-                     std::ostream &outs)
+                     std::ostream &outs,
+                     bool include_summary=true)
 {
    for (pkgCache::VerIterator Ver = P.VersionList();
 {
    for (pkgCache::VerIterator Ver = P.VersionList();
-        Ver.end() == false; Ver++) 
-      ListSingleVersion(CacheFile, records, Ver, outs);
+        Ver.end() == false; ++Ver)
+   {
+      ListSingleVersion(CacheFile, records, Ver, outs, include_summary);
+      outs << "\n";
+   }
 }
 }
-
+                                                                       /*}}}*/
 // list - list package based on criteria                               /*{{{*/
 // ---------------------------------------------------------------------
 // list - list package based on criteria                               /*{{{*/
 // ---------------------------------------------------------------------
-bool List(CommandLine &Cmd)
+bool DoList(CommandLine &Cmd)
 {
    pkgCacheFile CacheFile;
    pkgCache *Cache = CacheFile.GetPkgCache();
 {
    pkgCacheFile CacheFile;
    pkgCache *Cache = CacheFile.GetPkgCache();
-   pkgRecords records(CacheFile);
-
    if (unlikely(Cache == NULL))
       return false;
    if (unlikely(Cache == NULL))
       return false;
+   pkgRecords records(CacheFile);
 
    const char **patterns;
    const char *all_pattern[] = { "*", NULL};
 
    const char **patterns;
    const char *all_pattern[] = { "*", NULL};
@@ -124,24 +120,27 @@ bool List(CommandLine &Cmd)
    std::map<std::string, std::string> output_map;
    std::map<std::string, std::string>::const_iterator K;
 
    std::map<std::string, std::string> output_map;
    std::map<std::string, std::string>::const_iterator K;
 
+   bool includeSummary = _config->FindB("APT::Cmd::List-Include-Summary");
+
    PackageNameMatcher matcher(patterns);
    LocalitySortedVersionSet bag;
    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);
    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++)
+   bool ShowAllVersions = _config->FindB("APT::Cmd::All-Versions", false);
+   for (LocalitySortedVersionSet::iterator V = bag.begin(); V != bag.end(); ++V)
    {
       std::stringstream outs;
    {
       std::stringstream outs;
-      if(_config->FindB("APT::Cmd::AllVersions", false) == true)
+      if(ShowAllVersions == true)
       {
       {
-         ListAllVersions(CacheFile, records, V.ParentPkg(), outs);
+         ListAllVersions(CacheFile, records, V.ParentPkg(), outs, includeSummary);
          output_map.insert(std::make_pair<std::string, std::string>(
             V.ParentPkg().Name(), outs.str()));
       } else {
          output_map.insert(std::make_pair<std::string, std::string>(
             V.ParentPkg().Name(), outs.str()));
       } else {
-         ListSingleVersion(CacheFile, records, V, outs);
+         ListSingleVersion(CacheFile, records, V, outs, includeSummary);
          output_map.insert(std::make_pair<std::string, std::string>(
                            V.ParentPkg().Name(), outs.str()));
       }
          output_map.insert(std::make_pair<std::string, std::string>(
                            V.ParentPkg().Name(), outs.str()));
       }
@@ -149,10 +148,22 @@ bool List(CommandLine &Cmd)
 
    // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status)
    // output the sorted map
 
    // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status)
    // output the sorted map
-   for (K = output_map.begin(); K != output_map.end(); K++)
+   for (K = output_map.begin(); K != output_map.end(); ++K)
       std::cout << (*K).second << std::endl;
 
 
       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;
 }
 
    return true;
 }