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