]>
git.saurik.com Git - apt.git/blob - apt-pkg/srcrecords.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: srcrecords.cc,v 1.2 1999/04/07 05:30:18 jgg 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/configuration.h>
21 #include <apt-pkg/strutl.h>
22 #include <apt-pkg/debsrcrecords.h>
25 // SrcRecords::pkgSrcRecords - Constructor /*{{{*/
26 // ---------------------------------------------------------------------
27 /* Open all the source index files */
28 pkgSrcRecords::pkgSrcRecords(pkgSourceList
&List
) : Files(0), Current(0)
30 pkgSourceList::const_iterator I
= List
.begin();
32 // Count how many items we will need
33 unsigned int Count
= 0;
34 for (; I
!= List
.end(); I
++)
35 if (I
->Type
== pkgSourceList::Item::DebSrc
)
38 // Doesnt work without any source index files
41 _error
->Error("Sorry, you must put some 'source' uris"
42 " in your sources.list");
46 Files
= new Parser
*[Count
+1];
47 memset(Files
,0,sizeof(*Files
)*(Count
+1));
49 // Create the parser objects
51 string Dir
= _config
->FindDir("Dir::State::lists");
52 for (I
= List
.begin(); I
!= List
.end(); I
++)
54 if (I
->Type
!= pkgSourceList::Item::DebSrc
)
58 FileFd
*FD
= new FileFd(Dir
+ URItoFileName(I
->PackagesURI()),
60 if (_error
->PendingError() == true)
66 Files
[Count
] = new debSrcRecordParser(FD
,I
);
73 // SrcRecords::~pkgSrcRecords - Destructor /*{{{*/
74 // ---------------------------------------------------------------------
76 pkgSrcRecords::~pkgSrcRecords()
81 // Blow away all the parser objects
82 for (unsigned int Count
= 0; Files
[Count
] != 0; Count
++)
86 // SrcRecords::Restart - Restart the search /*{{{*/
87 // ---------------------------------------------------------------------
88 /* Return all of the parsers to their starting position */
89 bool pkgSrcRecords::Restart()
92 for (Parser
**I
= Files
; *I
!= 0; I
++)
93 if ((*I
)->Restart() == false)
98 // SrcRecords::Find - Find the first source package with the given name /*{{{*/
99 // ---------------------------------------------------------------------
100 /* This searches on both source package names and output binary names and
101 returns the first found. A 'cursor' like system is used to allow this
102 function to be called multiple times to get successive entries */
103 pkgSrcRecords::Parser
*pkgSrcRecords::Find(const char *Package
,bool SrcOnly
)
110 // Step to the next record, possibly switching files
111 while ((*Current
)->Step() == false)
113 if (_error
->PendingError() == true)
121 if (_error
->PendingError() == true)
125 if ((*Current
)->Package() == Package
)
131 // Check for a binary hit
132 const char **I
= (*Current
)->Binaries();
133 for (; I
!= 0 && *I
!= 0; I
++)
134 if (strcmp(Package
,*I
) == 0)