debrecords.cc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. #include <apt-pkg/debrecords.h>
  10. #include <apt-pkg/strutl.h>
  11. #include <apt-pkg/error.h>
  12. #include <langinfo.h>
  13. /*}}}*/
  14. // RecordParser::debRecordParser - Constructor /*{{{*/
  15. // ---------------------------------------------------------------------
  16. /* */
  17. debRecordParser::debRecordParser(string FileName,pkgCache &Cache) :
  18. File(FileName,FileFd::ReadOnly),
  19. Tags(&File,Cache.Head().MaxVerFileSize + 200)
  20. {
  21. }
  22. /*}}}*/
  23. // RecordParser::Jump - Jump to a specific record /*{{{*/
  24. // ---------------------------------------------------------------------
  25. /* */
  26. bool debRecordParser::Jump(pkgCache::VerFileIterator const &Ver)
  27. {
  28. return Tags.Jump(Section,Ver->Offset);
  29. }
  30. bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc)
  31. {
  32. return Tags.Jump(Section,Desc->Offset);
  33. }
  34. /*}}}*/
  35. // RecordParser::FileName - Return the archive filename on the site /*{{{*/
  36. // ---------------------------------------------------------------------
  37. /* */
  38. string debRecordParser::FileName()
  39. {
  40. return Section.FindS("Filename");
  41. }
  42. /*}}}*/
  43. // RecordParser::Name - Return the package name /*{{{*/
  44. // ---------------------------------------------------------------------
  45. /* */
  46. string debRecordParser::Name()
  47. {
  48. return Section.FindS("Package");
  49. }
  50. /*}}}*/
  51. // RecordParser::MD5Hash - Return the archive hash /*{{{*/
  52. // ---------------------------------------------------------------------
  53. /* */
  54. string debRecordParser::MD5Hash()
  55. {
  56. return Section.FindS("MD5Sum");
  57. }
  58. /*}}}*/
  59. // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
  60. // ---------------------------------------------------------------------
  61. /* */
  62. string debRecordParser::SHA1Hash()
  63. {
  64. return Section.FindS("SHA1");
  65. }
  66. /*}}}*/
  67. // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
  68. // ---------------------------------------------------------------------
  69. /* */
  70. string debRecordParser::SHA256Hash()
  71. {
  72. return Section.FindS("SHA256");
  73. }
  74. /*}}}*/
  75. // RecordParser::Maintainer - Return the maintainer email /*{{{*/
  76. // ---------------------------------------------------------------------
  77. /* */
  78. string debRecordParser::Maintainer()
  79. {
  80. return Section.FindS("Maintainer");
  81. }
  82. /*}}}*/
  83. // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
  84. // ---------------------------------------------------------------------
  85. /* */
  86. string debRecordParser::ShortDesc()
  87. {
  88. string Res = LongDesc();
  89. string::size_type Pos = Res.find('\n');
  90. if (Pos == string::npos)
  91. return Res;
  92. return string(Res,0,Pos);
  93. }
  94. /*}}}*/
  95. // RecordParser::LongDesc - Return a longer description /*{{{*/
  96. // ---------------------------------------------------------------------
  97. /* */
  98. string debRecordParser::LongDesc()
  99. {
  100. string orig, dest;
  101. char *codeset = nl_langinfo(CODESET);
  102. if (!Section.FindS("Description").empty())
  103. orig = Section.FindS("Description").c_str();
  104. else
  105. orig = Section.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str()).c_str();
  106. if (strcmp(codeset,"UTF-8") != 0) {
  107. UTF8ToCodeset(codeset, orig, &dest);
  108. orig = dest;
  109. }
  110. return orig;
  111. }
  112. /*}}}*/
  113. static const char *SourceVerSeparators = " ()";
  114. // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
  115. // ---------------------------------------------------------------------
  116. /* */
  117. string debRecordParser::SourcePkg()
  118. {
  119. string Res = Section.FindS("Source");
  120. string::size_type Pos = Res.find_first_of(SourceVerSeparators);
  121. if (Pos == string::npos)
  122. return Res;
  123. return string(Res,0,Pos);
  124. }
  125. /*}}}*/
  126. // RecordParser::SourceVer - Return the source version number if present /*{{{*/
  127. // ---------------------------------------------------------------------
  128. /* */
  129. string debRecordParser::SourceVer()
  130. {
  131. string Pkg = Section.FindS("Source");
  132. string::size_type Pos = Pkg.find_first_of(SourceVerSeparators);
  133. if (Pos == string::npos)
  134. return "";
  135. string::size_type VerStart = Pkg.find_first_not_of(SourceVerSeparators, Pos);
  136. if(VerStart == string::npos)
  137. return "";
  138. string::size_type VerEnd = Pkg.find_first_of(SourceVerSeparators, VerStart);
  139. if(VerEnd == string::npos)
  140. // Corresponds to the case of, e.g., "foo (1.2" without a closing
  141. // paren. Be liberal and guess what it means.
  142. return string(Pkg, VerStart);
  143. else
  144. return string(Pkg, VerStart, VerEnd - VerStart);
  145. }
  146. /*}}}*/
  147. // RecordParser::GetRec - Return the whole record /*{{{*/
  148. // ---------------------------------------------------------------------
  149. /* */
  150. void debRecordParser::GetRec(const char *&Start,const char *&Stop)
  151. {
  152. Section.GetSection(Start,Stop);
  153. }
  154. /*}}}*/