srcrecords.cc 3.9 KB

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