srcrecords.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: srcrecords.cc,v 1.5 2001/02/23 06:41:55 jgg 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. Files = new Parser *[List.end() - List.begin() + 1];
  26. unsigned int Count = 0;
  27. pkgSourceList::const_iterator I = List.begin();
  28. for (; I != List.end(); I++)
  29. {
  30. Files[Count] = (*I)->CreateSrcParser();
  31. if (_error->PendingError() == true)
  32. return;
  33. if (Files[Count] != 0)
  34. Count++;
  35. }
  36. Files[Count] = 0;
  37. // Doesn't work without any source index files
  38. if (Count == 0)
  39. {
  40. _error->Error(_("Sorry, 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. if (Files == 0)
  53. return;
  54. // Blow away all the parser objects
  55. for (unsigned int Count = 0; Files[Count] != 0; Count++)
  56. delete Files[Count];
  57. delete [] Files;
  58. }
  59. /*}}}*/
  60. // SrcRecords::Restart - Restart the search /*{{{*/
  61. // ---------------------------------------------------------------------
  62. /* Return all of the parsers to their starting position */
  63. bool pkgSrcRecords::Restart()
  64. {
  65. Current = Files;
  66. for (Parser **I = Files; *I != 0; I++)
  67. (*I)->Restart();
  68. return true;
  69. }
  70. /*}}}*/
  71. // SrcRecords::Find - Find the first source package with the given name /*{{{*/
  72. // ---------------------------------------------------------------------
  73. /* This searches on both source package names and output binary names and
  74. returns the first found. A 'cursor' like system is used to allow this
  75. function to be called multiple times to get successive entries */
  76. pkgSrcRecords::Parser *pkgSrcRecords::Find(const char *Package,bool SrcOnly)
  77. {
  78. if (*Current == 0)
  79. return 0;
  80. while (true)
  81. {
  82. // Step to the next record, possibly switching files
  83. while ((*Current)->Step() == false)
  84. {
  85. if (_error->PendingError() == true)
  86. return 0;
  87. Current++;
  88. if (*Current == 0)
  89. return 0;
  90. }
  91. // IO error somehow
  92. if (_error->PendingError() == true)
  93. return 0;
  94. // Source name hit
  95. if ((*Current)->Package() == Package)
  96. return *Current;
  97. if (SrcOnly == true)
  98. continue;
  99. // Check for a binary hit
  100. const char **I = (*Current)->Binaries();
  101. for (; I != 0 && *I != 0; I++)
  102. if (strcmp(Package,*I) == 0)
  103. return *Current;
  104. }
  105. }
  106. /*}}}*/
  107. // Parser::BuildDepType - Convert a build dep to a string /*{{{*/
  108. // ---------------------------------------------------------------------
  109. /* */
  110. const char *pkgSrcRecords::Parser::BuildDepType(unsigned char Type)
  111. {
  112. const char *fields[] = {"Build-Depends",
  113. "Build-Depends-Indep",
  114. "Build-Conflicts",
  115. "Build-Conflicts-Indep"};
  116. if (Type < 4)
  117. return fields[Type];
  118. else
  119. return "";
  120. }
  121. /*}}}*/