apt  2.2.4
About: Apt (Advanced Package Tool) is a management system for software packages (Debian/Ubuntu). Release series 2.2.
  Fossies Dox: apt-2.2.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

srcrecords.cc
Go to the documentation of this file.
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 /* ######################################################################
4 
5  Source Package Records - Allows access to source package records
6 
7  Parses and allows access to the list of source records and searching by
8  source name on that list.
9 
10  ##################################################################### */
11  /*}}}*/
12 // Include Files /*{{{*/
13 #include <config.h>
14 
15 #include <apt-pkg/debsrcrecords.h>
16 #include <apt-pkg/error.h>
17 #include <apt-pkg/indexfile.h>
18 #include <apt-pkg/macros.h>
19 #include <apt-pkg/metaindex.h>
20 #include <apt-pkg/sourcelist.h>
21 #include <apt-pkg/srcrecords.h>
22 
23 #include <string>
24 #include <vector>
25 #include <string.h>
26 
27 #include <apti18n.h>
28  /*}}}*/
29 
30 // SrcRecords::pkgSrcRecords - Constructor /*{{{*/
31 // ---------------------------------------------------------------------
32 /* Open all the source index files */
33 pkgSrcRecords::pkgSrcRecords(pkgSourceList &List) : d(NULL), Files(0)
34 {
35  for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); ++I)
36  {
37  std::vector<pkgIndexFile *> *Indexes = (*I)->GetIndexFiles();
38  for (std::vector<pkgIndexFile *>::const_iterator J = Indexes->begin();
39  J != Indexes->end(); ++J)
40  {
41  _error->PushToStack();
42  Parser* P = (*J)->CreateSrcParser();
43  bool const newError = _error->PendingError();
44  _error->MergeWithStack();
45  if (newError)
46  return;
47  if (P != 0)
48  Files.push_back(P);
49  }
50  }
51 
52  // Doesn't work without any source index files
53  if (Files.empty() == true)
54  {
55  _error->Error(_("You must put some 'deb-src' URIs"
56  " in your sources.list"));
57  return;
58  }
59 
60  Restart();
61 }
62  /*}}}*/
63 // SrcRecords::~pkgSrcRecords - Destructor /*{{{*/
64 // ---------------------------------------------------------------------
65 /* */
67 {
68  // Blow away all the parser objects
69  for(std::vector<Parser*>::iterator I = Files.begin(); I != Files.end(); ++I)
70  delete *I;
71 }
72  /*}}}*/
73 // SrcRecords::Restart - Restart the search /*{{{*/
74 // ---------------------------------------------------------------------
75 /* Return all of the parsers to their starting position */
77 {
78  Current = Files.begin();
79  for (std::vector<Parser*>::iterator I = Files.begin();
80  I != Files.end(); ++I)
81  if ((*I)->Offset() != 0)
82  (*I)->Restart();
83 
84  return true;
85 }
86  /*}}}*/
87 // SrcRecords::Step - Step to the next Source Record /*{{{*/
88 // ---------------------------------------------------------------------
89 /* Step to the next source package record */
91 {
92  if (Current == Files.end())
93  return 0;
94 
95  // Step to the next record, possibly switching files
96  while ((*Current)->Step() == false)
97  {
98  ++Current;
99  if (Current == Files.end())
100  return 0;
101  }
102 
103  return *Current;
104 }
105  /*}}}*/
106 // SrcRecords::Find - Find the first source package with the given name /*{{{*/
107 // ---------------------------------------------------------------------
108 /* This searches on both source package names and output binary names and
109  returns the first found. A 'cursor' like system is used to allow this
110  function to be called multiple times to get successive entries */
111 pkgSrcRecords::Parser *pkgSrcRecords::Find(const char *Package,bool const &SrcOnly)
112 {
113  while (true)
114  {
115  if(Step() == 0)
116  return 0;
117 
118  // Source name hit
119  if ((*Current)->Package() == Package)
120  return *Current;
121 
122  if (SrcOnly == true)
123  continue;
124 
125  // Check for a binary hit
126  const char **I = (*Current)->Binaries();
127  for (; I != 0 && *I != 0; ++I)
128  if (strcmp(Package,*I) == 0)
129  return *Current;
130  }
131 }
132  /*}}}*/
133 // Parser::BuildDepType - Convert a build dep to a string /*{{{*/
134 // ---------------------------------------------------------------------
135 /* */
136 const char *pkgSrcRecords::Parser::BuildDepType(unsigned char const &Type)
137 {
138  const char *fields[] = {"Build-Depends",
139  "Build-Depends-Indep",
140  "Build-Conflicts",
141  "Build-Conflicts-Indep",
142  "Build-Depends-Arch",
143  "Build-Conflicts-Arch"};
144  if (unlikely(Type >= sizeof(fields)/sizeof(fields[0])))
145  return "";
146  return fields[Type];
147 }
148  /*}}}*/
149 
150 
151 pkgSrcRecords::Parser::Parser(const pkgIndexFile *Index) : d(NULL), iIndex(Index) {}
static bool std::string const metaIndex const *const pkgAcqMetaClearSig *const pkgAcquire::Item *const I
const_iterator begin() const
Definition: sourcelist.h:97
const_iterator end() const
Definition: sourcelist.h:98
std::vector< metaIndex * >::const_iterator const_iterator
Definition: sourcelist.h:76
static const char * BuildDepType(unsigned char const &Type) APT_PURE
Definition: srcrecords.cc:136
Parser(const pkgIndexFile *Index)
Definition: srcrecords.cc:151
std::vector< Parser * >::iterator Current
Definition: srcrecords.h:89
std::vector< Parser * > Files
Definition: srcrecords.h:88
pkgSrcRecords(pkgSourceList &List)
Definition: srcrecords.cc:33
virtual ~pkgSrcRecords()
Definition: srcrecords.cc:66
bool Restart()
Definition: srcrecords.cc:76
Parser * Find(const char *Package, bool const &SrcOnly=false)
Definition: srcrecords.cc:111
const Parser * Step()
Definition: srcrecords.cc:90
void *const d
dpointer placeholder (for later in case we need it)
Definition: srcrecords.h:85