srcrecords.cc 3.8 KB

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