]> git.saurik.com Git - apt.git/blame - apt-pkg/deb/debrecords.cc
cleanup the debian/rules file a bit
[apt.git] / apt-pkg / deb / debrecords.cc
CommitLineData
f55ece0e
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
a7c835af 3// $Id: debrecords.cc,v 1.10 2001/03/13 06:51:46 jgg Exp $
f55ece0e
AL
4/* ######################################################################
5
6 Debian Package Records - Parser for debian package records
7
8 ##################################################################### */
9 /*}}}*/
10// Include Files /*{{{*/
f55ece0e 11#include <apt-pkg/debrecords.h>
a52f938b 12#include <apt-pkg/strutl.h>
f55ece0e 13#include <apt-pkg/error.h>
45df0ad2 14#include <apt-pkg/aptconfiguration.h>
a52f938b 15#include <langinfo.h>
f55ece0e
AL
16 /*}}}*/
17
18// RecordParser::debRecordParser - Constructor /*{{{*/
19// ---------------------------------------------------------------------
20/* */
b2e465d6 21debRecordParser::debRecordParser(string FileName,pkgCache &Cache) :
c4fc2fd7 22 File(FileName,FileFd::ReadOnlyGzip),
63b528a4
MV
23 Tags(&File, std::max(Cache.Head().MaxVerFileSize,
24 Cache.Head().MaxDescFileSize) + 200)
f55ece0e
AL
25{
26}
27 /*}}}*/
28// RecordParser::Jump - Jump to a specific record /*{{{*/
29// ---------------------------------------------------------------------
30/* */
03e39e59 31bool debRecordParser::Jump(pkgCache::VerFileIterator const &Ver)
f55ece0e
AL
32{
33 return Tags.Jump(Section,Ver->Offset);
a52f938b
OS
34}
35bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc)
36{
37 return Tags.Jump(Section,Desc->Offset);
f55ece0e
AL
38}
39 /*}}}*/
7e798dd7
AL
40// RecordParser::FileName - Return the archive filename on the site /*{{{*/
41// ---------------------------------------------------------------------
42/* */
43string debRecordParser::FileName()
44{
7974b907 45 return Section.FindS("Filename");
7e798dd7
AL
46}
47 /*}}}*/
b2e465d6
AL
48// RecordParser::Name - Return the package name /*{{{*/
49// ---------------------------------------------------------------------
50/* */
51string debRecordParser::Name()
52{
53 return Section.FindS("Package");
54}
55 /*}}}*/
f27b4a70
OS
56// RecordParser::Homepage - Return the package homepage /*{{{*/
57// ---------------------------------------------------------------------
58/* */
59string debRecordParser::Homepage()
60{
61 return Section.FindS("Homepage");
62}
63 /*}}}*/
7e798dd7
AL
64// RecordParser::MD5Hash - Return the archive hash /*{{{*/
65// ---------------------------------------------------------------------
66/* */
67string debRecordParser::MD5Hash()
68{
a7c835af
AL
69 return Section.FindS("MD5Sum");
70}
71 /*}}}*/
72// RecordParser::SHA1Hash - Return the archive hash /*{{{*/
73// ---------------------------------------------------------------------
74/* */
75string debRecordParser::SHA1Hash()
76{
59b46c41 77 return Section.FindS("SHA1");
7e798dd7
AL
78}
79 /*}}}*/
495e5cb2
MV
80// RecordParser::SHA1Hash - Return the archive hash /*{{{*/
81// ---------------------------------------------------------------------
82/* */
83string debRecordParser::SHA256Hash()
84{
85 return Section.FindS("SHA256");
86}
87 /*}}}*/
7e798dd7
AL
88// RecordParser::Maintainer - Return the maintainer email /*{{{*/
89// ---------------------------------------------------------------------
90/* */
91string debRecordParser::Maintainer()
92{
7974b907 93 return Section.FindS("Maintainer");
7e798dd7
AL
94}
95 /*}}}*/
96// RecordParser::ShortDesc - Return a 1 line description /*{{{*/
97// ---------------------------------------------------------------------
98/* */
99string debRecordParser::ShortDesc()
100{
a52f938b 101 string Res = LongDesc();
7e798dd7
AL
102 string::size_type Pos = Res.find('\n');
103 if (Pos == string::npos)
104 return Res;
105 return string(Res,0,Pos);
106}
107 /*}}}*/
108// RecordParser::LongDesc - Return a longer description /*{{{*/
109// ---------------------------------------------------------------------
110/* */
111string debRecordParser::LongDesc()
112{
a52f938b 113 string orig, dest;
a52f938b
OS
114
115 if (!Section.FindS("Description").empty())
116 orig = Section.FindS("Description").c_str();
45df0ad2
DK
117 else
118 {
119 vector<string> const lang = APT::Configuration::getLanguages();
120 for (vector<string>::const_iterator l = lang.begin();
121 orig.empty() && l != lang.end(); l++)
122 orig = Section.FindS(string("Description-").append(*l).c_str());
123 }
a52f938b 124
45df0ad2 125 char const * const codeset = nl_langinfo(CODESET);
a52f938b
OS
126 if (strcmp(codeset,"UTF-8") != 0) {
127 UTF8ToCodeset(codeset, orig, &dest);
128 orig = dest;
129 }
130
131 return orig;
7e798dd7
AL
132}
133 /*}}}*/
c2f2b862
MV
134
135static const char *SourceVerSeparators = " ()";
136
04f232fc 137// RecordParser::SourcePkg - Return the source package name if any /*{{{*/
36375005
AL
138// ---------------------------------------------------------------------
139/* */
140string debRecordParser::SourcePkg()
141{
04f232fc 142 string Res = Section.FindS("Source");
c2f2b862 143 string::size_type Pos = Res.find_first_of(SourceVerSeparators);
04f232fc
AL
144 if (Pos == string::npos)
145 return Res;
146 return string(Res,0,Pos);
36375005
AL
147}
148 /*}}}*/
c2f2b862
MV
149// RecordParser::SourceVer - Return the source version number if present /*{{{*/
150// ---------------------------------------------------------------------
151/* */
152string debRecordParser::SourceVer()
153{
154 string Pkg = Section.FindS("Source");
155 string::size_type Pos = Pkg.find_first_of(SourceVerSeparators);
156 if (Pos == string::npos)
157 return "";
158
159 string::size_type VerStart = Pkg.find_first_not_of(SourceVerSeparators, Pos);
160 if(VerStart == string::npos)
161 return "";
162
163 string::size_type VerEnd = Pkg.find_first_of(SourceVerSeparators, VerStart);
164 if(VerEnd == string::npos)
165 // Corresponds to the case of, e.g., "foo (1.2" without a closing
166 // paren. Be liberal and guess what it means.
167 return string(Pkg, VerStart);
168 else
169 return string(Pkg, VerStart, VerEnd - VerStart);
170}
171 /*}}}*/
b2e465d6
AL
172// RecordParser::GetRec - Return the whole record /*{{{*/
173// ---------------------------------------------------------------------
174/* */
175void debRecordParser::GetRec(const char *&Start,const char *&Stop)
176{
177 Section.GetSection(Start,Stop);
178}
179 /*}}}*/