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