debrecords.cc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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::Homepage - Return the package homepage /*{{{*/
  52. // ---------------------------------------------------------------------
  53. /* */
  54. string debRecordParser::Homepage()
  55. {
  56. return Section.FindS("Homepage");
  57. }
  58. /*}}}*/
  59. // RecordParser::MD5Hash - Return the archive hash /*{{{*/
  60. // ---------------------------------------------------------------------
  61. /* */
  62. string debRecordParser::MD5Hash()
  63. {
  64. return Section.FindS("MD5Sum");
  65. }
  66. /*}}}*/
  67. // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
  68. // ---------------------------------------------------------------------
  69. /* */
  70. string debRecordParser::SHA1Hash()
  71. {
  72. return Section.FindS("SHA1");
  73. }
  74. /*}}}*/
  75. // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
  76. // ---------------------------------------------------------------------
  77. /* */
  78. string debRecordParser::SHA256Hash()
  79. {
  80. return Section.FindS("SHA256");
  81. }
  82. /*}}}*/
  83. // RecordParser::Maintainer - Return the maintainer email /*{{{*/
  84. // ---------------------------------------------------------------------
  85. /* */
  86. string debRecordParser::Maintainer()
  87. {
  88. return Section.FindS("Maintainer");
  89. }
  90. /*}}}*/
  91. // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
  92. // ---------------------------------------------------------------------
  93. /* */
  94. string debRecordParser::ShortDesc()
  95. {
  96. string Res = LongDesc();
  97. string::size_type Pos = Res.find('\n');
  98. if (Pos == string::npos)
  99. return Res;
  100. return string(Res,0,Pos);
  101. }
  102. /*}}}*/
  103. // RecordParser::LongDesc - Return a longer description /*{{{*/
  104. // ---------------------------------------------------------------------
  105. /* */
  106. string debRecordParser::LongDesc()
  107. {
  108. string orig, dest;
  109. char *codeset = nl_langinfo(CODESET);
  110. if (!Section.FindS("Description").empty())
  111. orig = Section.FindS("Description").c_str();
  112. else
  113. orig = Section.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str()).c_str();
  114. if (strcmp(codeset,"UTF-8") != 0) {
  115. UTF8ToCodeset(codeset, orig, &dest);
  116. orig = dest;
  117. }
  118. return orig;
  119. }
  120. /*}}}*/
  121. static const char *SourceVerSeparators = " ()";
  122. // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
  123. // ---------------------------------------------------------------------
  124. /* */
  125. string debRecordParser::SourcePkg()
  126. {
  127. string Res = Section.FindS("Source");
  128. string::size_type Pos = Res.find_first_of(SourceVerSeparators);
  129. if (Pos == string::npos)
  130. return Res;
  131. return string(Res,0,Pos);
  132. }
  133. /*}}}*/
  134. // RecordParser::SourceVer - Return the source version number if present /*{{{*/
  135. // ---------------------------------------------------------------------
  136. /* */
  137. string debRecordParser::SourceVer()
  138. {
  139. string Pkg = Section.FindS("Source");
  140. string::size_type Pos = Pkg.find_first_of(SourceVerSeparators);
  141. if (Pos == string::npos)
  142. return "";
  143. string::size_type VerStart = Pkg.find_first_not_of(SourceVerSeparators, Pos);
  144. if(VerStart == string::npos)
  145. return "";
  146. string::size_type VerEnd = Pkg.find_first_of(SourceVerSeparators, VerStart);
  147. if(VerEnd == string::npos)
  148. // Corresponds to the case of, e.g., "foo (1.2" without a closing
  149. // paren. Be liberal and guess what it means.
  150. return string(Pkg, VerStart);
  151. else
  152. return string(Pkg, VerStart, VerEnd - VerStart);
  153. }
  154. /*}}}*/
  155. // RecordParser::GetRec - Return the whole record /*{{{*/
  156. // ---------------------------------------------------------------------
  157. /* */
  158. void debRecordParser::GetRec(const char *&Start,const char *&Stop)
  159. {
  160. Section.GetSection(Start,Stop);
  161. }
  162. /*}}}*/