]>
Commit | Line | Data |
---|---|---|
b9179170 MV |
1 | // Include Files /*{{{*/ |
2 | #include <config.h> | |
3 | ||
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> | |
24 | ||
25 | #include <sstream> | |
26 | #include <vector> | |
27 | #include <utility> | |
28 | #include <cassert> | |
29 | #include <locale.h> | |
30 | #include <iostream> | |
31 | #include <unistd.h> | |
32 | #include <errno.h> | |
33 | #include <regex.h> | |
34 | #include <stdio.h> | |
35 | #include <algorithm> | |
36 | ||
37 | #include "private-cmndline.h" | |
38 | #include "private-list.h" | |
39 | #include "private-output.h" | |
40 | #include "private-cacheset.h" | |
41 | ||
42 | #include <apti18n.h> | |
43 | /*}}}*/ | |
44 | ||
ee0167c4 | 45 | struct PackageSortAlphabetic /*{{{*/ |
b9179170 MV |
46 | { |
47 | bool operator () (const pkgCache::PkgIterator &p_lhs, | |
48 | const pkgCache::PkgIterator &p_rhs) | |
49 | { | |
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); | |
53 | } | |
54 | }; | |
ee0167c4 DK |
55 | /*}}}*/ |
56 | class PackageNameMatcher : public Matcher /*{{{*/ | |
57 | { | |
dd4d9729 MV |
58 | #ifdef PACKAGE_MATCHER_ABI_COMPAT |
59 | #define PackageMatcher PackageNameMatchesFnmatch | |
60 | #endif | |
b9179170 MV |
61 | public: |
62 | PackageNameMatcher(const char **patterns) | |
63 | { | |
9ce3cfc9 | 64 | for(int i=0; patterns[i] != NULL; ++i) |
b9179170 MV |
65 | { |
66 | std::string pattern = patterns[i]; | |
dd4d9729 MV |
67 | #ifdef PACKAGE_MATCHER_ABI_COMPAT |
68 | APT::CacheFilter::PackageNameMatchesFnmatch *cachefilter = NULL; | |
69 | cachefilter = new APT::CacheFilter::PackageNameMatchesFnmatch(pattern); | |
70 | #else | |
b9179170 | 71 | APT::CacheFilter::PackageMatcher *cachefilter = NULL; |
c1a61d1c | 72 | if(_config->FindB("APT::Cmd::Use-Regexp", false) == true) |
b9179170 MV |
73 | cachefilter = new APT::CacheFilter::PackageNameMatchesRegEx(pattern); |
74 | else | |
75 | cachefilter = new APT::CacheFilter::PackageNameMatchesFnmatch(pattern); | |
dd4d9729 | 76 | #endif |
b9179170 MV |
77 | filters.push_back(cachefilter); |
78 | } | |
79 | } | |
80 | virtual ~PackageNameMatcher() | |
81 | { | |
9ce3cfc9 | 82 | for(J=filters.begin(); J != filters.end(); ++J) |
b9179170 MV |
83 | delete *J; |
84 | } | |
85 | virtual bool operator () (const pkgCache::PkgIterator &P) | |
86 | { | |
9ce3cfc9 | 87 | for(J=filters.begin(); J != filters.end(); ++J) |
b9179170 MV |
88 | { |
89 | APT::CacheFilter::PackageMatcher *cachefilter = *J; | |
90 | if((*cachefilter)(P)) | |
91 | return true; | |
92 | } | |
93 | return false; | |
94 | } | |
95 | ||
96 | private: | |
97 | std::vector<APT::CacheFilter::PackageMatcher*> filters; | |
98 | std::vector<APT::CacheFilter::PackageMatcher*>::const_iterator J; | |
dd4d9729 | 99 | #undef PackageMatcher |
b9179170 | 100 | }; |
ee0167c4 DK |
101 | /*}}}*/ |
102 | void ListAllVersions(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/ | |
b9179170 | 103 | pkgCache::PkgIterator P, |
14109555 MV |
104 | std::ostream &outs, |
105 | bool include_summary=true) | |
b9179170 MV |
106 | { |
107 | for (pkgCache::VerIterator Ver = P.VersionList(); | |
796673c3 | 108 | Ver.end() == false; ++Ver) |
14109555 MV |
109 | { |
110 | ListSingleVersion(CacheFile, records, Ver, outs, include_summary); | |
111 | outs << "\n"; | |
112 | } | |
b9179170 | 113 | } |
ee0167c4 | 114 | /*}}}*/ |
b9179170 MV |
115 | // list - list package based on criteria /*{{{*/ |
116 | // --------------------------------------------------------------------- | |
117 | bool List(CommandLine &Cmd) | |
118 | { | |
119 | pkgCacheFile CacheFile; | |
120 | pkgCache *Cache = CacheFile.GetPkgCache(); | |
121 | pkgRecords records(CacheFile); | |
122 | ||
123 | if (unlikely(Cache == NULL)) | |
124 | return false; | |
125 | ||
126 | const char **patterns; | |
127 | const char *all_pattern[] = { "*", NULL}; | |
128 | ||
129 | if (strv_length(Cmd.FileList + 1) == 0) | |
130 | { | |
131 | patterns = all_pattern; | |
132 | } else { | |
133 | patterns = Cmd.FileList + 1; | |
134 | } | |
135 | ||
136 | std::map<std::string, std::string> output_map; | |
137 | std::map<std::string, std::string>::const_iterator K; | |
138 | ||
e1dc051a MV |
139 | bool includeSummary = _config->FindB("APT::Cmd::List-Include-Summary"); |
140 | ||
b9179170 MV |
141 | PackageNameMatcher matcher(patterns); |
142 | LocalitySortedVersionSet bag; | |
14109555 | 143 | OpTextProgress progress(*_config); |
b9179170 MV |
144 | progress.OverallProgress(0, |
145 | Cache->Head().PackageCount, | |
146 | Cache->Head().PackageCount, | |
147 | _("Listing")); | |
148 | GetLocalitySortedVersionSet(CacheFile, bag, matcher, progress); | |
9ce3cfc9 | 149 | for (LocalitySortedVersionSet::iterator V = bag.begin(); V != bag.end(); ++V) |
b9179170 MV |
150 | { |
151 | std::stringstream outs; | |
c1a61d1c | 152 | if(_config->FindB("APT::Cmd::All-Versions", false) == true) |
b9179170 | 153 | { |
14109555 | 154 | ListAllVersions(CacheFile, records, V.ParentPkg(), outs, includeSummary); |
b9179170 MV |
155 | output_map.insert(std::make_pair<std::string, std::string>( |
156 | V.ParentPkg().Name(), outs.str())); | |
157 | } else { | |
e1dc051a | 158 | ListSingleVersion(CacheFile, records, V, outs, includeSummary); |
b9179170 MV |
159 | output_map.insert(std::make_pair<std::string, std::string>( |
160 | V.ParentPkg().Name(), outs.str())); | |
161 | } | |
162 | } | |
163 | ||
164 | // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status) | |
165 | // output the sorted map | |
9ce3cfc9 | 166 | for (K = output_map.begin(); K != output_map.end(); ++K) |
b9179170 MV |
167 | std::cout << (*K).second << std::endl; |
168 | ||
169 | ||
170 | return true; | |
171 | } | |
172 |