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