]> git.saurik.com Git - apt.git/blame - apt-pkg/deb/debrecords.cc
Merge branch 'debian/sid' into debian/experimental
[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 /*}}}*/
b3501edb
DK
76// RecordParser::Hashes - return the available archive hashes /*{{{*/
77HashStringList debRecordParser::Hashes() const
d9b9e9e2 78{
b3501edb
DK
79 HashStringList hashes;
80 for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type)
81 {
82 std::string const hash = Section.FindS(*type);
83 if (hash.empty() == false)
84 hashes.push_back(HashString(*type, hash));
85 }
86 return hashes;
d9b9e9e2
MV
87}
88 /*}}}*/
7e798dd7
AL
89// RecordParser::Maintainer - Return the maintainer email /*{{{*/
90// ---------------------------------------------------------------------
91/* */
92string debRecordParser::Maintainer()
93{
7974b907 94 return Section.FindS("Maintainer");
7e798dd7
AL
95}
96 /*}}}*/
75bda619
MV
97// RecordParser::RecordField - Return the value of an arbitrary field /*{{*/
98// ---------------------------------------------------------------------
99/* */
100string debRecordParser::RecordField(const char *fieldName)
101{
102 return Section.FindS(fieldName);
103}
104
105 /*}}}*/
7e798dd7
AL
106// RecordParser::ShortDesc - Return a 1 line description /*{{{*/
107// ---------------------------------------------------------------------
108/* */
ffe3c68e 109string debRecordParser::ShortDesc(std::string const &lang)
7e798dd7 110{
ffe3c68e
DK
111 string const Res = LongDesc(lang);
112 if (Res.empty() == true)
113 return "";
114 string::size_type const Pos = Res.find('\n');
7e798dd7
AL
115 if (Pos == string::npos)
116 return Res;
117 return string(Res,0,Pos);
118}
119 /*}}}*/
120// RecordParser::LongDesc - Return a longer description /*{{{*/
121// ---------------------------------------------------------------------
122/* */
ffe3c68e 123string debRecordParser::LongDesc(std::string const &lang)
7e798dd7 124{
ffe3c68e
DK
125 string orig;
126 if (lang.empty() == true)
127 {
128 std::vector<string> const lang = APT::Configuration::getLanguages();
129 for (std::vector<string>::const_iterator l = lang.begin();
130 l != lang.end(); ++l)
131 {
132 std::string const tagname = "Description-" + *l;
133 orig = Section.FindS(tagname.c_str());
134 if (orig.empty() == false)
135 break;
136 else if (*l == "en")
137 {
138 orig = Section.FindS("Description");
139 if (orig.empty() == false)
140 break;
141 }
142 }
143 if (orig.empty() == true)
144 orig = Section.FindS("Description");
145 }
146 else
147 {
148 std::string const tagname = "Description-" + lang;
149 orig = Section.FindS(tagname.c_str());
150 if (orig.empty() == true && lang == "en")
151 orig = Section.FindS("Description");
152 }
a52f938b 153
ffe3c68e
DK
154 char const * const codeset = nl_langinfo(CODESET);
155 if (strcmp(codeset,"UTF-8") != 0) {
156 string dest;
157 UTF8ToCodeset(codeset, orig, &dest);
158 return dest;
159 }
a52f938b 160
a52f938b 161 return orig;
7e798dd7
AL
162}
163 /*}}}*/
c2f2b862
MV
164
165static const char *SourceVerSeparators = " ()";
166
04f232fc 167// RecordParser::SourcePkg - Return the source package name if any /*{{{*/
36375005
AL
168// ---------------------------------------------------------------------
169/* */
170string debRecordParser::SourcePkg()
171{
04f232fc 172 string Res = Section.FindS("Source");
c2f2b862 173 string::size_type Pos = Res.find_first_of(SourceVerSeparators);
04f232fc
AL
174 if (Pos == string::npos)
175 return Res;
176 return string(Res,0,Pos);
36375005
AL
177}
178 /*}}}*/
c2f2b862
MV
179// RecordParser::SourceVer - Return the source version number if present /*{{{*/
180// ---------------------------------------------------------------------
181/* */
182string debRecordParser::SourceVer()
183{
184 string Pkg = Section.FindS("Source");
185 string::size_type Pos = Pkg.find_first_of(SourceVerSeparators);
186 if (Pos == string::npos)
187 return "";
188
189 string::size_type VerStart = Pkg.find_first_not_of(SourceVerSeparators, Pos);
190 if(VerStart == string::npos)
191 return "";
192
193 string::size_type VerEnd = Pkg.find_first_of(SourceVerSeparators, VerStart);
194 if(VerEnd == string::npos)
195 // Corresponds to the case of, e.g., "foo (1.2" without a closing
196 // paren. Be liberal and guess what it means.
197 return string(Pkg, VerStart);
198 else
199 return string(Pkg, VerStart, VerEnd - VerStart);
200}
201 /*}}}*/
b2e465d6
AL
202// RecordParser::GetRec - Return the whole record /*{{{*/
203// ---------------------------------------------------------------------
204/* */
205void debRecordParser::GetRec(const char *&Start,const char *&Stop)
206{
207 Section.GetSection(Start,Stop);
208}
209 /*}}}*/
862bafea 210
9d653a6d 211debRecordParser::~debRecordParser() {}