debrecords.cc 4.8 KB

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