srcrecords.cc 3.8 KB

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