srcrecords.cc 3.8 KB

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