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