]> git.saurik.com Git - apt.git/blob - apt-pkg/srcrecords.cc
move ByHash into its own function
[apt.git] / apt-pkg / srcrecords.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: srcrecords.cc,v 1.7.2.2 2003/12/26 16:27:34 mdz Exp $
4 /* ######################################################################
5
6 Source Package Records - Allows access to source package records
7
8 Parses and allows access to the list of source records and searching by
9 source name on that list.
10
11 ##################################################################### */
12 /*}}}*/
13 // Include Files /*{{{*/
14 #include<config.h>
15
16 #include <apt-pkg/srcrecords.h>
17 #include <apt-pkg/error.h>
18 #include <apt-pkg/sourcelist.h>
19 #include <apt-pkg/metaindex.h>
20 #include <apt-pkg/indexfile.h>
21 #include <apt-pkg/macros.h>
22
23 #include <string.h>
24 #include <string>
25 #include <vector>
26
27 #include <apti18n.h>
28 /*}}}*/
29
30 // SrcRecords::pkgSrcRecords - Constructor /*{{{*/
31 // ---------------------------------------------------------------------
32 /* Open all the source index files */
33 pkgSrcRecords::pkgSrcRecords(pkgSourceList &List) : d(NULL), Files(0), Current(0)
34 {
35 for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); ++I)
36 {
37 std::vector<pkgIndexFile *> *Indexes = (*I)->GetIndexFiles();
38 for (std::vector<pkgIndexFile *>::const_iterator J = Indexes->begin();
39 J != Indexes->end(); ++J)
40 {
41 Parser* P = (*J)->CreateSrcParser();
42 if (_error->PendingError() == true)
43 return;
44 if (P != 0)
45 Files.push_back(P);
46 }
47 }
48
49 // Doesn't work without any source index files
50 if (Files.empty() == true)
51 {
52 _error->Error(_("You must put some 'source' URIs"
53 " in your sources.list"));
54 return;
55 }
56
57 Restart();
58 }
59 /*}}}*/
60 // SrcRecords::~pkgSrcRecords - Destructor /*{{{*/
61 // ---------------------------------------------------------------------
62 /* */
63 pkgSrcRecords::~pkgSrcRecords()
64 {
65 // Blow away all the parser objects
66 for(std::vector<Parser*>::iterator I = Files.begin(); I != Files.end(); ++I)
67 delete *I;
68 }
69 /*}}}*/
70 // SrcRecords::Restart - Restart the search /*{{{*/
71 // ---------------------------------------------------------------------
72 /* Return all of the parsers to their starting position */
73 bool pkgSrcRecords::Restart()
74 {
75 Current = Files.begin();
76 for (std::vector<Parser*>::iterator I = Files.begin();
77 I != Files.end(); ++I)
78 if ((*I)->Offset() != 0)
79 (*I)->Restart();
80
81 return true;
82 }
83 /*}}}*/
84 // SrcRecords::Find - Find the first source package with the given name /*{{{*/
85 // ---------------------------------------------------------------------
86 /* This searches on both source package names and output binary names and
87 returns the first found. A 'cursor' like system is used to allow this
88 function to be called multiple times to get successive entries */
89 pkgSrcRecords::Parser *pkgSrcRecords::Find(const char *Package,bool const &SrcOnly)
90 {
91 if (Current == Files.end())
92 return 0;
93
94 while (true)
95 {
96 // Step to the next record, possibly switching files
97 while ((*Current)->Step() == false)
98 {
99 if (_error->PendingError() == true)
100 return 0;
101 ++Current;
102 if (Current == Files.end())
103 return 0;
104 }
105
106 // IO error somehow
107 if (_error->PendingError() == true)
108 return 0;
109
110 // Source name hit
111 if ((*Current)->Package() == Package)
112 return *Current;
113
114 if (SrcOnly == true)
115 continue;
116
117 // Check for a binary hit
118 const char **I = (*Current)->Binaries();
119 for (; I != 0 && *I != 0; ++I)
120 if (strcmp(Package,*I) == 0)
121 return *Current;
122 }
123 }
124 /*}}}*/
125 // Parser::BuildDepType - Convert a build dep to a string /*{{{*/
126 // ---------------------------------------------------------------------
127 /* */
128 const char *pkgSrcRecords::Parser::BuildDepType(unsigned char const &Type)
129 {
130 const char *fields[] = {"Build-Depends",
131 "Build-Depends-Indep",
132 "Build-Conflicts",
133 "Build-Conflicts-Indep"};
134 if (unlikely(Type >= sizeof(fields)/sizeof(fields[0])))
135 return "";
136 return fields[Type];
137 }
138 /*}}}*/
139
140