srcrecords.cc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: srcrecords.cc,v 1.7.2.2 2003/12/26 16:27:34 mdz Exp $
  4. /* ######################################################################
  5. Source Package Records - Allows access to source package records
  6. Parses and allows access to the list of source records and searching by
  7. source name on that list.
  8. ##################################################################### */
  9. /*}}}*/
  10. // Include Files /*{{{*/
  11. #ifdef __GNUG__
  12. #pragma implementation "apt-pkg/srcrecords.h"
  13. #endif
  14. #include <apt-pkg/srcrecords.h>
  15. #include <apt-pkg/error.h>
  16. #include <apt-pkg/sourcelist.h>
  17. #include <apt-pkg/strutl.h>
  18. #include <apti18n.h>
  19. /*}}}*/
  20. // SrcRecords::pkgSrcRecords - Constructor /*{{{*/
  21. // ---------------------------------------------------------------------
  22. /* Open all the source index files */
  23. pkgSrcRecords::pkgSrcRecords(pkgSourceList &List) : Files(0), Current(0)
  24. {
  25. for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); I++)
  26. {
  27. vector<pkgIndexFile *> *Indexes = (*I)->GetIndexFiles();
  28. for (vector<pkgIndexFile *>::const_iterator J = Indexes->begin();
  29. J != Indexes->end(); J++)
  30. {
  31. Parser* P = (*J)->CreateSrcParser();
  32. if (_error->PendingError() == true)
  33. return;
  34. if (P != 0)
  35. Files.push_back(P);
  36. }
  37. }
  38. // Doesn't work without any source index files
  39. if (Files.size() == 0)
  40. {
  41. _error->Error(_("You must put some 'source' URIs"
  42. " in your sources.list"));
  43. return;
  44. }
  45. Restart();
  46. }
  47. /*}}}*/
  48. // SrcRecords::~pkgSrcRecords - Destructor /*{{{*/
  49. // ---------------------------------------------------------------------
  50. /* */
  51. pkgSrcRecords::~pkgSrcRecords()
  52. {
  53. // Blow away all the parser objects
  54. for(vector<Parser*>::iterator I = Files.begin(); I != Files.end(); ++I)
  55. delete *I;
  56. }
  57. /*}}}*/
  58. // SrcRecords::Restart - Restart the search /*{{{*/
  59. // ---------------------------------------------------------------------
  60. /* Return all of the parsers to their starting position */
  61. bool pkgSrcRecords::Restart()
  62. {
  63. Current = Files.begin();
  64. for (vector<Parser*>::iterator I = Files.begin();
  65. I != Files.end(); I++)
  66. (*I)->Restart();
  67. return true;
  68. }
  69. /*}}}*/
  70. // SrcRecords::Find - Find the first source package with the given name /*{{{*/
  71. // ---------------------------------------------------------------------
  72. /* This searches on both source package names and output binary names and
  73. returns the first found. A 'cursor' like system is used to allow this
  74. function to be called multiple times to get successive entries */
  75. pkgSrcRecords::Parser *pkgSrcRecords::Find(const char *Package,bool SrcOnly)
  76. {
  77. if (Current == Files.end())
  78. return 0;
  79. while (true)
  80. {
  81. // Step to the next record, possibly switching files
  82. while ((*Current)->Step() == false)
  83. {
  84. if (_error->PendingError() == true)
  85. return 0;
  86. Current++;
  87. if (Current == Files.end())
  88. return 0;
  89. }
  90. // IO error somehow
  91. if (_error->PendingError() == true)
  92. return 0;
  93. // Source name hit
  94. if ((*Current)->Package() == Package)
  95. return *Current;
  96. if (SrcOnly == true)
  97. continue;
  98. // Check for a binary hit
  99. const char **I = (*Current)->Binaries();
  100. for (; I != 0 && *I != 0; I++)
  101. if (strcmp(Package,*I) == 0)
  102. return *Current;
  103. }
  104. }
  105. /*}}}*/
  106. // Parser::BuildDepType - Convert a build dep to a string /*{{{*/
  107. // ---------------------------------------------------------------------
  108. /* */
  109. const char *pkgSrcRecords::Parser::BuildDepType(unsigned char Type)
  110. {
  111. const char *fields[] = {"Build-Depends",
  112. "Build-Depends-Indep",
  113. "Build-Conflicts",
  114. "Build-Conflicts-Indep"};
  115. if (Type < 4)
  116. return fields[Type];
  117. else
  118. return "";
  119. }
  120. /*}}}*/