You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

159 lines
4.7 KiB

  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: debsrcrecords.cc,v 1.6 2004/03/17 05:58:54 mdz Exp $
  4. /* ######################################################################
  5. Debian Source Package Records - Parser implementation for Debian style
  6. source indexes
  7. ##################################################################### */
  8. /*}}}*/
  9. // Include Files /*{{{*/
  10. #ifdef __GNUG__
  11. #pragma implementation "apt-pkg/debsrcrecords.h"
  12. #endif
  13. #include <apt-pkg/deblistparser.h>
  14. #include <apt-pkg/debsrcrecords.h>
  15. #include <apt-pkg/error.h>
  16. #include <apt-pkg/strutl.h>
  17. #include <apt-pkg/configuration.h>
  18. using std::max;
  19. /*}}}*/
  20. // SrcRecordParser::Binaries - Return the binaries field /*{{{*/
  21. // ---------------------------------------------------------------------
  22. /* This member parses the binaries field into a pair of class arrays and
  23. returns a list of strings representing all of the components of the
  24. binaries field. The returned array need not be freed and will be
  25. reused by the next Binaries function call. This function is commonly
  26. used during scanning to find the right package */
  27. const char **debSrcRecordParser::Binaries()
  28. {
  29. // This should use Start/Stop too, it is supposed to be efficient after all.
  30. string Bins = Sect.FindS("Binary");
  31. if (Bins.empty() == true || Bins.length() >= 102400)
  32. return 0;
  33. if (Bins.length() >= BufSize)
  34. {
  35. delete [] Buffer;
  36. // allocate new size based on buffer (but never smaller than 4000)
  37. BufSize = max((unsigned int)4000, max((unsigned int)Bins.length()+1,2*BufSize));
  38. Buffer = new char[BufSize];
  39. }
  40. strcpy(Buffer,Bins.c_str());
  41. if (TokSplitString(',',Buffer,StaticBinList,
  42. sizeof(StaticBinList)/sizeof(StaticBinList[0])) == false)
  43. return 0;
  44. return (const char **)StaticBinList;
  45. }
  46. /*}}}*/
  47. // SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/
  48. // ---------------------------------------------------------------------
  49. /* This member parses the build-depends information and returns a list of
  50. package/version records representing the build dependency. The returned
  51. array need not be freed and will be reused by the next call to this
  52. function */
  53. bool debSrcRecordParser::BuildDepends(vector<pkgSrcRecords::Parser::BuildDepRec> &BuildDeps, bool ArchOnly)
  54. {
  55. unsigned int I;
  56. const char *Start, *Stop;
  57. BuildDepRec rec;
  58. const char *fields[] = {"Build-Depends",
  59. "Build-Depends-Indep",
  60. "Build-Conflicts",
  61. "Build-Conflicts-Indep"};
  62. BuildDeps.clear();
  63. for (I = 0; I < 4; I++)
  64. {
  65. if (ArchOnly && (I == 1 || I == 3))
  66. continue;
  67. if (Sect.Find(fields[I], Start, Stop) == false)
  68. continue;
  69. while (1)
  70. {
  71. Start = debListParser::ParseDepends(Start, Stop,
  72. rec.Package,rec.Version,rec.Op,true);
  73. if (Start == 0)
  74. return _error->Error("Problem parsing dependency: %s", fields[I]);
  75. rec.Type = I;
  76. if (rec.Package != "")
  77. BuildDeps.push_back(rec);
  78. if (Start == Stop)
  79. break;
  80. }
  81. }
  82. return true;
  83. }
  84. /*}}}*/
  85. // SrcRecordParser::Files - Return a list of files for this source /*{{{*/
  86. // ---------------------------------------------------------------------
  87. /* This parses the list of files and returns it, each file is required to have
  88. a complete source package */
  89. bool debSrcRecordParser::Files(vector<pkgSrcRecords::File> &List)
  90. {
  91. List.erase(List.begin(),List.end());
  92. string Files = Sect.FindS("Files");
  93. if (Files.empty() == true)
  94. return false;
  95. // Stash the / terminated directory prefix
  96. string Base = Sect.FindS("Directory");
  97. if (Base.empty() == false && Base[Base.length()-1] != '/')
  98. Base += '/';
  99. // Iterate over the entire list grabbing each triplet
  100. const char *C = Files.c_str();
  101. while (*C != 0)
  102. {
  103. pkgSrcRecords::File F;
  104. string Size;
  105. // Parse each of the elements
  106. if (ParseQuoteWord(C,F.MD5Hash) == false ||
  107. ParseQuoteWord(C,Size) == false ||
  108. ParseQuoteWord(C,F.Path) == false)
  109. return _error->Error("Error parsing file record");
  110. // Parse the size and append the directory
  111. F.Size = atoi(Size.c_str());
  112. F.Path = Base + F.Path;
  113. // Try to guess what sort of file it is we are getting.
  114. string::size_type Pos = F.Path.length()-1;
  115. while (1)
  116. {
  117. string::size_type Tmp = F.Path.rfind('.',Pos);
  118. if (Tmp == string::npos)
  119. break;
  120. F.Type = string(F.Path,Tmp+1,Pos-Tmp);
  121. if (F.Type == "gz" || F.Type == "bz2")
  122. {
  123. Pos = Tmp-1;
  124. continue;
  125. }
  126. break;
  127. }
  128. List.push_back(F);
  129. }
  130. return true;
  131. }
  132. /*}}}*/