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