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