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