]>
git.saurik.com Git - apt.git/blob - apt-pkg/srcrecords.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: srcrecords.cc,v 1.7 2002/11/09 20:38:02 doogie Exp $
4 /* ######################################################################
6 Source Package Records - Allows access to source package records
8 Parses and allows access to the list of source records and searching by
9 source name on that list.
11 ##################################################################### */
13 // Include Files /*{{{*/
15 #pragma implementation "apt-pkg/srcrecords.h"
18 #include <apt-pkg/srcrecords.h>
19 #include <apt-pkg/error.h>
20 #include <apt-pkg/sourcelist.h>
21 #include <apt-pkg/strutl.h>
26 // SrcRecords::pkgSrcRecords - Constructor /*{{{*/
27 // ---------------------------------------------------------------------
28 /* Open all the source index files */
29 pkgSrcRecords::pkgSrcRecords(pkgSourceList
&List
) : Files(0), Current(0)
31 Files
= new Parser
*[List
.end() - List
.begin() + 1];
32 memset(Files
,0,sizeof(*Files
)*(List
.end() - List
.begin() + 1));
34 unsigned int Count
= 0;
35 pkgSourceList::const_iterator I
= List
.begin();
36 for (; I
!= List
.end(); I
++)
38 Files
[Count
] = (*I
)->CreateSrcParser();
39 if (_error
->PendingError() == true)
41 if (Files
[Count
] != 0)
46 // Doesn't work without any source index files
49 _error
->Error(_("You must put some 'source' URIs"
50 " in your sources.list"));
57 // SrcRecords::~pkgSrcRecords - Destructor /*{{{*/
58 // ---------------------------------------------------------------------
60 pkgSrcRecords::~pkgSrcRecords()
65 // Blow away all the parser objects
66 for (unsigned int Count
= 0; Files
[Count
] != 0; Count
++)
71 // SrcRecords::Restart - Restart the search /*{{{*/
72 // ---------------------------------------------------------------------
73 /* Return all of the parsers to their starting position */
74 bool pkgSrcRecords::Restart()
77 for (Parser
**I
= Files
; *I
!= 0; I
++)
83 // SrcRecords::Find - Find the first source package with the given name /*{{{*/
84 // ---------------------------------------------------------------------
85 /* This searches on both source package names and output binary names and
86 returns the first found. A 'cursor' like system is used to allow this
87 function to be called multiple times to get successive entries */
88 pkgSrcRecords::Parser
*pkgSrcRecords::Find(const char *Package
,bool SrcOnly
)
95 // Step to the next record, possibly switching files
96 while ((*Current
)->Step() == false)
98 if (_error
->PendingError() == true)
106 if (_error
->PendingError() == true)
110 if ((*Current
)->Package() == Package
)
116 // Check for a binary hit
117 const char **I
= (*Current
)->Binaries();
118 for (; I
!= 0 && *I
!= 0; I
++)
119 if (strcmp(Package
,*I
) == 0)
124 // Parser::BuildDepType - Convert a build dep to a string /*{{{*/
125 // ---------------------------------------------------------------------
127 const char *pkgSrcRecords::Parser::BuildDepType(unsigned char Type
)
129 const char *fields
[] = {"Build-Depends",
130 "Build-Depends-Indep",
132 "Build-Conflicts-Indep"};