]> git.saurik.com Git - apt.git/blob - apt-private/private-search.cc
add autopkgtest
[apt.git] / apt-private / private-search.cc
1 // Includes /*{{{*/
2 #include <apt-pkg/error.h>
3 #include <apt-pkg/cachefile.h>
4 #include <apt-pkg/cachefilter.h>
5 #include <apt-pkg/cacheset.h>
6 #include <apt-pkg/init.h>
7 #include <apt-pkg/progress.h>
8 #include <apt-pkg/sourcelist.h>
9 #include <apt-pkg/cmndline.h>
10 #include <apt-pkg/strutl.h>
11 #include <apt-pkg/fileutl.h>
12 #include <apt-pkg/pkgrecords.h>
13 #include <apt-pkg/srcrecords.h>
14 #include <apt-pkg/version.h>
15 #include <apt-pkg/policy.h>
16 #include <apt-pkg/tagfile.h>
17 #include <apt-pkg/algorithms.h>
18 #include <apt-pkg/sptr.h>
19 #include <apt-pkg/pkgsystem.h>
20 #include <apt-pkg/indexfile.h>
21 #include <apt-pkg/metaindex.h>
22
23 #include <sstream>
24 #include <utility>
25 #include <cassert>
26 #include <locale.h>
27 #include <iostream>
28 #include <unistd.h>
29 #include <errno.h>
30 #include <regex.h>
31 #include <stdio.h>
32 #include <iomanip>
33 #include <algorithm>
34 #include <map>
35
36 #include "private-search.h"
37 #include "private-cacheset.h"
38 /*}}}*/
39
40 bool FullTextSearch(CommandLine &CmdL) /*{{{*/
41 {
42 pkgCacheFile CacheFile;
43 pkgCache *Cache = CacheFile.GetPkgCache();
44 pkgDepCache::Policy *Plcy = CacheFile.GetPolicy();
45 pkgRecords records(CacheFile);
46 if (unlikely(Cache == NULL || Plcy == NULL))
47 return false;
48
49 const char **patterns;
50 patterns = CmdL.FileList + 1;
51
52 std::map<std::string, std::string> output_map;
53 std::map<std::string, std::string>::const_iterator K;
54
55 LocalitySortedVersionSet bag;
56 OpTextProgress progress;
57 progress.OverallProgress(0, 100, 50, _("Sorting"));
58 GetLocalitySortedVersionSet(CacheFile, bag, progress);
59 LocalitySortedVersionSet::iterator V = bag.begin();
60
61 progress.OverallProgress(50, 100, 50, _("Full Text Search"));
62 progress.SubProgress(bag.size());
63 int Done = 0;
64 for ( ;V != bag.end(); V++)
65 {
66 if (Done%500 == 0)
67 progress.Progress(Done);
68 Done++;
69
70 int i;
71 pkgCache::DescIterator Desc = V.TranslatedDescription();
72 pkgRecords::Parser &parser = records.Lookup(Desc.FileList());
73
74 bool all_found = true;
75 for(i=0; patterns[i] != NULL; i++)
76 {
77 // FIXME: use regexp instead of simple find()
78 const char *pattern = patterns[i];
79 all_found &= (
80 strstr(V.ParentPkg().Name(), pattern) != NULL ||
81 parser.ShortDesc().find(pattern) != std::string::npos ||
82 parser.LongDesc().find(pattern) != std::string::npos);
83 }
84 if (all_found)
85 {
86 std::stringstream outs;
87 ListSingleVersion(CacheFile, records, V, outs);
88 output_map.insert(std::make_pair<std::string, std::string>(
89 V.ParentPkg().Name(), outs.str()));
90 }
91 }
92 progress.Done();
93
94 // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status)
95 // output the sorted map
96 for (K = output_map.begin(); K != output_map.end(); K++)
97 std::cout << (*K).second << std::endl;
98
99 return true;
100 }
101 /*}}}*/