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