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