debsrcrecords.cc 4.4 KB

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