]> git.saurik.com Git - apt.git/blame - apt-private/private-search.cc
warning: cast from type A to type B casts away qualifiers [-Wcast-qual]
[apt.git] / apt-private / private-search.cc
CommitLineData
ee0167c4 1// Includes /*{{{*/
b9179170
MV
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"
ee0167c4 38 /*}}}*/
b9179170 39
ee0167c4 40bool FullTextSearch(CommandLine &CmdL) /*{{{*/
b9179170
MV
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;
1bef0dd5 56 OpTextProgress progress(*_config);
b9179170
MV
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;
9ce3cfc9 64 for ( ;V != bag.end(); ++V)
b9179170
MV
65 {
66 if (Done%500 == 0)
67 progress.Progress(Done);
9ce3cfc9 68 ++Done;
b9179170
MV
69
70 int i;
71 pkgCache::DescIterator Desc = V.TranslatedDescription();
72 pkgRecords::Parser &parser = records.Lookup(Desc.FileList());
73
74 bool all_found = true;
9ce3cfc9 75 for(i=0; patterns[i] != NULL; ++i)
b9179170
MV
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
9ce3cfc9 96 for (K = output_map.begin(); K != output_map.end(); ++K)
b9179170
MV
97 std::cout << (*K).second << std::endl;
98
99 return true;
100}
ee0167c4 101 /*}}}*/