debsrcrecords.cc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: debsrcrecords.cc,v 1.3 1999/04/07 05:30:18 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/debsrcrecords.h>
  14. #include <apt-pkg/error.h>
  15. #include <apt-pkg/strutl.h>
  16. /*}}}*/
  17. // SrcRecordParser::Binaries - Return the binaries field /*{{{*/
  18. // ---------------------------------------------------------------------
  19. /* This member parses the binaries field into a pair of class arrays and
  20. returns a list of strings representing all of the components of the
  21. binaries field. The returned array need not be freed and will be
  22. reused by the next Binaries function call. */
  23. const char **debSrcRecordParser::Binaries()
  24. {
  25. string Bins = Sect.FindS("Binary");
  26. char *Buf = Buffer;
  27. unsigned int Bin = 0;
  28. if (Bins.empty() == true)
  29. return 0;
  30. // Strip any leading spaces
  31. string::const_iterator Start = Bins.begin();
  32. for (; Start != Bins.end() && isspace(*Start) != 0; Start++);
  33. string::const_iterator Pos = Start;
  34. while (Pos != Bins.end())
  35. {
  36. // Skip to the next ','
  37. for (; Pos != Bins.end() && *Pos != ','; Pos++);
  38. // Back remove spaces
  39. string::const_iterator End = Pos;
  40. for (; End > Start && (End[-1] == ',' || isspace(End[-1]) != 0); End--);
  41. // Stash the string
  42. memcpy(Buf,Start,End-Start);
  43. StaticBinList[Bin] = Buf;
  44. Bin++;
  45. Buf += End-Start;
  46. *Buf++ = 0;
  47. // Advance pos
  48. for (; Pos != Bins.end() && (*Pos == ',' || isspace(*Pos) != 0); Pos++);
  49. Start = Pos;
  50. }
  51. StaticBinList[Bin] = 0;
  52. return StaticBinList;
  53. }
  54. /*}}}*/
  55. // SrcRecordParser::Files - Return a list of files for this source /*{{{*/
  56. // ---------------------------------------------------------------------
  57. /* This parses the list of files and returns it, each file is required to have
  58. a complete source package */
  59. bool debSrcRecordParser::Files(vector<pkgSrcRecords::File> &List)
  60. {
  61. List.erase(List.begin(),List.end());
  62. string Files = Sect.FindS("Files");
  63. if (Files.empty() == true)
  64. return false;
  65. // Stash the / terminated directory prefix
  66. string Base = Sect.FindS("Directory");
  67. if (Base.empty() == false && Base[Base.length()-1] != '/')
  68. Base += '/';
  69. // Iterate over the entire list grabbing each triplet
  70. const char *C = Files.c_str();
  71. while (*C != 0)
  72. {
  73. pkgSrcRecords::File F;
  74. string Size;
  75. // Parse each of the elements
  76. if (ParseQuoteWord(C,F.MD5Hash) == false ||
  77. ParseQuoteWord(C,Size) == false ||
  78. ParseQuoteWord(C,F.Path) == false)
  79. return _error->Error("Error parsing file record");
  80. // Parse the size and append the directory
  81. F.Size = atoi(Size.c_str());
  82. F.Path = Base + F.Path;
  83. List.push_back(F);
  84. }
  85. return true;
  86. }
  87. /*}}}*/