debrecords.cc 4.8 KB

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