1 // Include Files /*{{{*/
4 #include <apt-pkg/error.h>
5 #include <apt-pkg/cachefile.h>
6 #include <apt-pkg/cachefilter.h>
7 #include <apt-pkg/cacheset.h>
8 #include <apt-pkg/init.h>
9 #include <apt-pkg/progress.h>
10 #include <apt-pkg/sourcelist.h>
11 #include <apt-pkg/cmndline.h>
12 #include <apt-pkg/strutl.h>
13 #include <apt-pkg/fileutl.h>
14 #include <apt-pkg/pkgrecords.h>
15 #include <apt-pkg/srcrecords.h>
16 #include <apt-pkg/version.h>
17 #include <apt-pkg/policy.h>
18 #include <apt-pkg/tagfile.h>
19 #include <apt-pkg/algorithms.h>
20 #include <apt-pkg/sptr.h>
21 #include <apt-pkg/pkgsystem.h>
22 #include <apt-pkg/indexfile.h>
23 #include <apt-pkg/metaindex.h>
37 #include "private-cmndline.h"
38 #include "private-list.h"
39 #include "private-output.h"
40 #include "private-cacheset.h"
45 struct PackageSortAlphabetic
47 bool operator () (const pkgCache::PkgIterator
&p_lhs
,
48 const pkgCache::PkgIterator
&p_rhs
)
50 const std::string
&l_name
= p_lhs
.FullName(true);
51 const std::string
&r_name
= p_rhs
.FullName(true);
52 return (l_name
< r_name
);
56 class PackageNameMatcher
: public Matcher
59 PackageNameMatcher(const char **patterns
)
61 for(int i
=0; patterns
[i
] != NULL
; i
++)
63 std::string pattern
= patterns
[i
];
64 APT::CacheFilter::PackageMatcher
*cachefilter
= NULL
;
65 if(_config
->FindB("APT::Cmd::UseRegexp", false) == true)
66 cachefilter
= new APT::CacheFilter::PackageNameMatchesRegEx(pattern
);
68 cachefilter
= new APT::CacheFilter::PackageNameMatchesFnmatch(pattern
);
69 filters
.push_back(cachefilter
);
72 virtual ~PackageNameMatcher()
74 for(J
=filters
.begin(); J
!= filters
.end(); J
++)
77 virtual bool operator () (const pkgCache::PkgIterator
&P
)
79 for(J
=filters
.begin(); J
!= filters
.end(); J
++)
81 APT::CacheFilter::PackageMatcher
*cachefilter
= *J
;
89 std::vector
<APT::CacheFilter::PackageMatcher
*> filters
;
90 std::vector
<APT::CacheFilter::PackageMatcher
*>::const_iterator J
;
95 void ListAllVersions(pkgCacheFile
&CacheFile
, pkgRecords
&records
,
96 pkgCache::PkgIterator P
,
99 for (pkgCache::VerIterator Ver
= P
.VersionList();
100 Ver
.end() == false; Ver
++)
101 ListSingleVersion(CacheFile
, records
, Ver
, outs
);
104 // list - list package based on criteria /*{{{*/
105 // ---------------------------------------------------------------------
106 bool List(CommandLine
&Cmd
)
108 pkgCacheFile CacheFile
;
109 pkgCache
*Cache
= CacheFile
.GetPkgCache();
110 pkgRecords
records(CacheFile
);
112 if (unlikely(Cache
== NULL
))
115 const char **patterns
;
116 const char *all_pattern
[] = { "*", NULL
};
118 if (strv_length(Cmd
.FileList
+ 1) == 0)
120 patterns
= all_pattern
;
122 patterns
= Cmd
.FileList
+ 1;
125 std::map
<std::string
, std::string
> output_map
;
126 std::map
<std::string
, std::string
>::const_iterator K
;
128 PackageNameMatcher
matcher(patterns
);
129 LocalitySortedVersionSet bag
;
130 OpTextProgress progress
;
131 progress
.OverallProgress(0,
132 Cache
->Head().PackageCount
,
133 Cache
->Head().PackageCount
,
135 GetLocalitySortedVersionSet(CacheFile
, bag
, matcher
, progress
);
136 for (LocalitySortedVersionSet::iterator V
= bag
.begin(); V
!= bag
.end(); V
++)
138 std::stringstream outs
;
139 if(_config
->FindB("APT::Cmd::AllVersions", false) == true)
141 ListAllVersions(CacheFile
, records
, V
.ParentPkg(), outs
);
142 output_map
.insert(std::make_pair
<std::string
, std::string
>(
143 V
.ParentPkg().Name(), outs
.str()));
145 ListSingleVersion(CacheFile
, records
, V
, outs
);
146 output_map
.insert(std::make_pair
<std::string
, std::string
>(
147 V
.ParentPkg().Name(), outs
.str()));
151 // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status)
152 // output the sorted map
153 for (K
= output_map
.begin(); K
!= output_map
.end(); K
++)
154 std::cout
<< (*K
).second
<< std::endl
;