]> git.saurik.com Git - apt.git/blame - apt-pkg/srcrecords.cc
show in madison command again also source packages (LP: #614589)
[apt.git] / apt-pkg / srcrecords.cc
CommitLineData
11e7af84
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
b3d44315 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 /*{{{*/
11e7af84
AL
14#include <apt-pkg/srcrecords.h>
15#include <apt-pkg/error.h>
b2e465d6 16#include <apt-pkg/sourcelist.h>
11e7af84 17#include <apt-pkg/strutl.h>
b2e465d6
AL
18
19#include <apti18n.h>
11e7af84
AL
20 /*}}}*/
21
22// SrcRecords::pkgSrcRecords - Constructor /*{{{*/
23// ---------------------------------------------------------------------
24/* Open all the source index files */
25pkgSrcRecords::pkgSrcRecords(pkgSourceList &List) : Files(0), Current(0)
26{
b3d44315 27 for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); I++)
b2e465d6 28 {
b3d44315
MV
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 }
b2e465d6 39 }
b2e465d6 40
0e72dd52 41 // Doesn't work without any source index files
b3d44315 42 if (Files.size() == 0)
11e7af84 43 {
677cbcbc 44 _error->Error(_("You must put some 'source' URIs"
b2e465d6 45 " in your sources.list"));
11e7af84
AL
46 return;
47 }
48
11e7af84
AL
49 Restart();
50}
51 /*}}}*/
52// SrcRecords::~pkgSrcRecords - Destructor /*{{{*/
53// ---------------------------------------------------------------------
54/* */
55pkgSrcRecords::~pkgSrcRecords()
56{
11e7af84 57 // Blow away all the parser objects
b3d44315
MV
58 for(vector<Parser*>::iterator I = Files.begin(); I != Files.end(); ++I)
59 delete *I;
11e7af84
AL
60}
61 /*}}}*/
62// SrcRecords::Restart - Restart the search /*{{{*/
63// ---------------------------------------------------------------------
64/* Return all of the parsers to their starting position */
65bool pkgSrcRecords::Restart()
66{
b3d44315
MV
67 Current = Files.begin();
68 for (vector<Parser*>::iterator I = Files.begin();
69 I != Files.end(); I++)
aaee8293
AL
70 (*I)->Restart();
71
11e7af84
AL
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 */
41c81fd8 80pkgSrcRecords::Parser *pkgSrcRecords::Find(const char *Package,bool const &SrcOnly)
11e7af84 81{
b3d44315 82 if (Current == Files.end())
11e7af84
AL
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++;
b3d44315 93 if (Current == Files.end())
11e7af84
AL
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 /*}}}*/
b2e465d6
AL
116// Parser::BuildDepType - Convert a build dep to a string /*{{{*/
117// ---------------------------------------------------------------------
118/* */
41c81fd8 119const char *pkgSrcRecords::Parser::BuildDepType(unsigned char const &Type)
b2e465d6
AL
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
11e7af84 132