]> git.saurik.com Git - apt.git/blob - apt-pkg/srcrecords.cc
Bug 87390
[apt.git] / apt-pkg / srcrecords.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: srcrecords.cc,v 1.5 2001/02/23 06:41:55 jgg 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 #ifdef __GNUG__
15 #pragma implementation "apt-pkg/srcrecords.h"
16 #endif
17
18 #include <apt-pkg/srcrecords.h>
19 #include <apt-pkg/error.h>
20 #include <apt-pkg/sourcelist.h>
21 #include <apt-pkg/strutl.h>
22
23 #include <apti18n.h>
24 /*}}}*/
25
26 // SrcRecords::pkgSrcRecords - Constructor /*{{{*/
27 // ---------------------------------------------------------------------
28 /* Open all the source index files */
29 pkgSrcRecords::pkgSrcRecords(pkgSourceList &List) : Files(0), Current(0)
30 {
31 Files = new Parser *[List.end() - List.begin() + 1];
32
33 unsigned int Count = 0;
34 pkgSourceList::const_iterator I = List.begin();
35 for (; I != List.end(); I++)
36 {
37 Files[Count] = (*I)->CreateSrcParser();
38 if (_error->PendingError() == true)
39 return;
40 if (Files[Count] != 0)
41 Count++;
42 }
43 Files[Count] = 0;
44
45 // Doesn't work without any source index files
46 if (Count == 0)
47 {
48 _error->Error(_("Sorry, you must put some 'source' URIs"
49 " in your sources.list"));
50 return;
51 }
52
53 Restart();
54 }
55 /*}}}*/
56 // SrcRecords::~pkgSrcRecords - Destructor /*{{{*/
57 // ---------------------------------------------------------------------
58 /* */
59 pkgSrcRecords::~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];
67 delete [] Files;
68 }
69 /*}}}*/
70 // SrcRecords::Restart - Restart the search /*{{{*/
71 // ---------------------------------------------------------------------
72 /* Return all of the parsers to their starting position */
73 bool pkgSrcRecords::Restart()
74 {
75 Current = Files;
76 for (Parser **I = Files; *I != 0; I++)
77 (*I)->Restart();
78
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 */
87 pkgSrcRecords::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 /*}}}*/
123 // Parser::BuildDepType - Convert a build dep to a string /*{{{*/
124 // ---------------------------------------------------------------------
125 /* */
126 const 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
139