]> git.saurik.com Git - apt.git/blame - apt-pkg/deb/debrecords.cc
Support large files in the complete toolset. Indexes of this
[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 /*}}}*/
106// RecordParser::ShortDesc - Return a 1 line description /*{{{*/
107// ---------------------------------------------------------------------
108/* */
109string debRecordParser::ShortDesc()
110{
a52f938b 111 string Res = LongDesc();
7e798dd7
AL
112 string::size_type Pos = Res.find('\n');
113 if (Pos == string::npos)
114 return Res;
115 return string(Res,0,Pos);
116}
117 /*}}}*/
118// RecordParser::LongDesc - Return a longer description /*{{{*/
119// ---------------------------------------------------------------------
120/* */
121string debRecordParser::LongDesc()
122{
a52f938b 123 string orig, dest;
a52f938b
OS
124
125 if (!Section.FindS("Description").empty())
126 orig = Section.FindS("Description").c_str();
45df0ad2
DK
127 else
128 {
129 vector<string> const lang = APT::Configuration::getLanguages();
130 for (vector<string>::const_iterator l = lang.begin();
131 orig.empty() && l != lang.end(); l++)
132 orig = Section.FindS(string("Description-").append(*l).c_str());
133 }
a52f938b 134
45df0ad2 135 char const * const codeset = nl_langinfo(CODESET);
a52f938b
OS
136 if (strcmp(codeset,"UTF-8") != 0) {
137 UTF8ToCodeset(codeset, orig, &dest);
138 orig = dest;
139 }
140
141 return orig;
7e798dd7
AL
142}
143 /*}}}*/
c2f2b862
MV
144
145static const char *SourceVerSeparators = " ()";
146
04f232fc 147// RecordParser::SourcePkg - Return the source package name if any /*{{{*/
36375005
AL
148// ---------------------------------------------------------------------
149/* */
150string debRecordParser::SourcePkg()
151{
04f232fc 152 string Res = Section.FindS("Source");
c2f2b862 153 string::size_type Pos = Res.find_first_of(SourceVerSeparators);
04f232fc
AL
154 if (Pos == string::npos)
155 return Res;
156 return string(Res,0,Pos);
36375005
AL
157}
158 /*}}}*/
c2f2b862
MV
159// RecordParser::SourceVer - Return the source version number if present /*{{{*/
160// ---------------------------------------------------------------------
161/* */
162string debRecordParser::SourceVer()
163{
164 string Pkg = Section.FindS("Source");
165 string::size_type Pos = Pkg.find_first_of(SourceVerSeparators);
166 if (Pos == string::npos)
167 return "";
168
169 string::size_type VerStart = Pkg.find_first_not_of(SourceVerSeparators, Pos);
170 if(VerStart == string::npos)
171 return "";
172
173 string::size_type VerEnd = Pkg.find_first_of(SourceVerSeparators, VerStart);
174 if(VerEnd == string::npos)
175 // Corresponds to the case of, e.g., "foo (1.2" without a closing
176 // paren. Be liberal and guess what it means.
177 return string(Pkg, VerStart);
178 else
179 return string(Pkg, VerStart, VerEnd - VerStart);
180}
181 /*}}}*/
b2e465d6
AL
182// RecordParser::GetRec - Return the whole record /*{{{*/
183// ---------------------------------------------------------------------
184/* */
185void debRecordParser::GetRec(const char *&Start,const char *&Stop)
186{
187 Section.GetSection(Start,Stop);
188}
189 /*}}}*/