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