debrecords.cc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: debrecords.cc,v 1.10 2001/03/13 06:51:46 jgg Exp $
  4. /* ######################################################################
  5. Debian Package Records - Parser for debian package records
  6. ##################################################################### */
  7. /*}}}*/
  8. // Include Files /*{{{*/
  9. #ifdef __GNUG__
  10. #pragma implementation "apt-pkg/debrecords.h"
  11. #endif
  12. #include <apt-pkg/debrecords.h>
  13. #include <apt-pkg/error.h>
  14. /*}}}*/
  15. // RecordParser::debRecordParser - Constructor /*{{{*/
  16. // ---------------------------------------------------------------------
  17. /* */
  18. debRecordParser::debRecordParser(string FileName,pkgCache &Cache) :
  19. File(FileName,FileFd::ReadOnly),
  20. Tags(&File,Cache.Head().MaxVerFileSize + 200)
  21. {
  22. }
  23. /*}}}*/
  24. // RecordParser::Jump - Jump to a specific record /*{{{*/
  25. // ---------------------------------------------------------------------
  26. /* */
  27. bool debRecordParser::Jump(pkgCache::VerFileIterator const &Ver)
  28. {
  29. return Tags.Jump(Section,Ver->Offset);
  30. }
  31. /*}}}*/
  32. // RecordParser::FileName - Return the archive filename on the site /*{{{*/
  33. // ---------------------------------------------------------------------
  34. /* */
  35. string debRecordParser::FileName()
  36. {
  37. return Section.FindS("Filename");
  38. }
  39. /*}}}*/
  40. // RecordParser::Name - Return the package name /*{{{*/
  41. // ---------------------------------------------------------------------
  42. /* */
  43. string debRecordParser::Name()
  44. {
  45. return Section.FindS("Package");
  46. }
  47. /*}}}*/
  48. // RecordParser::MD5Hash - Return the archive hash /*{{{*/
  49. // ---------------------------------------------------------------------
  50. /* */
  51. string debRecordParser::MD5Hash()
  52. {
  53. return Section.FindS("MD5Sum");
  54. }
  55. /*}}}*/
  56. // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
  57. // ---------------------------------------------------------------------
  58. /* */
  59. string debRecordParser::SHA1Hash()
  60. {
  61. return Section.FindS("SHA1");
  62. }
  63. /*}}}*/
  64. // RecordParser::Maintainer - Return the maintainer email /*{{{*/
  65. // ---------------------------------------------------------------------
  66. /* */
  67. string debRecordParser::Maintainer()
  68. {
  69. return Section.FindS("Maintainer");
  70. }
  71. /*}}}*/
  72. // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
  73. // ---------------------------------------------------------------------
  74. /* */
  75. string debRecordParser::ShortDesc()
  76. {
  77. string Res = Section.FindS("Description");
  78. string::size_type Pos = Res.find('\n');
  79. if (Pos == string::npos)
  80. return Res;
  81. return string(Res,0,Pos);
  82. }
  83. /*}}}*/
  84. // RecordParser::LongDesc - Return a longer description /*{{{*/
  85. // ---------------------------------------------------------------------
  86. /* */
  87. string debRecordParser::LongDesc()
  88. {
  89. return Section.FindS("Description");
  90. }
  91. /*}}}*/
  92. static const char *SourceVerSeparators = " ()";
  93. // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
  94. // ---------------------------------------------------------------------
  95. /* */
  96. string debRecordParser::SourcePkg()
  97. {
  98. string Res = Section.FindS("Source");
  99. string::size_type Pos = Res.find_first_of(SourceVerSeparators);
  100. if (Pos == string::npos)
  101. return Res;
  102. return string(Res,0,Pos);
  103. }
  104. /*}}}*/
  105. // RecordParser::SourceVer - Return the source version number if present /*{{{*/
  106. // ---------------------------------------------------------------------
  107. /* */
  108. string debRecordParser::SourceVer()
  109. {
  110. string Pkg = Section.FindS("Source");
  111. string::size_type Pos = Pkg.find_first_of(SourceVerSeparators);
  112. if (Pos == string::npos)
  113. return "";
  114. string::size_type VerStart = Pkg.find_first_not_of(SourceVerSeparators, Pos);
  115. if(VerStart == string::npos)
  116. return "";
  117. string::size_type VerEnd = Pkg.find_first_of(SourceVerSeparators, VerStart);
  118. if(VerEnd == string::npos)
  119. // Corresponds to the case of, e.g., "foo (1.2" without a closing
  120. // paren. Be liberal and guess what it means.
  121. return string(Pkg, VerStart);
  122. else
  123. return string(Pkg, VerStart, VerEnd - VerStart);
  124. }
  125. /*}}}*/
  126. // RecordParser::GetRec - Return the whole record /*{{{*/
  127. // ---------------------------------------------------------------------
  128. /* */
  129. void debRecordParser::GetRec(const char *&Start,const char *&Stop)
  130. {
  131. Section.GetSection(Start,Stop);
  132. }
  133. /*}}}*/