]> git.saurik.com Git - apt.git/blame - apt-pkg/deb/debrecords.cc
parse arch-qualified Provides correctly
[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>
2f6a2fbb 14#include <apt-pkg/debindexfile.h>
a52f938b 15#include <apt-pkg/strutl.h>
45df0ad2 16#include <apt-pkg/aptconfiguration.h>
472ff00e 17#include <apt-pkg/fileutl.h>
453b82a3
DK
18#include <apt-pkg/cacheiterators.h>
19#include <apt-pkg/pkgcache.h>
20#include <apt-pkg/tagfile.h>
2f6a2fbb 21#include <apt-pkg/error.h>
472ff00e 22
453b82a3
DK
23#include <string.h>
24#include <algorithm>
2f6a2fbb 25#include <sstream>
453b82a3
DK
26#include <string>
27#include <vector>
a52f938b 28#include <langinfo.h>
2f6a2fbb
DK
29
30#include <apti18n.h>
f55ece0e
AL
31 /*}}}*/
32
8f3ba4e8
DK
33using std::string;
34
f55ece0e 35// RecordParser::debRecordParser - Constructor /*{{{*/
2f6a2fbb
DK
36debRecordParser::debRecordParser(string FileName,pkgCache &Cache) :
37 debRecordParserBase(), File(FileName, FileFd::ReadOnly, FileFd::Extension),
38 Tags(&File, std::max(Cache.Head().MaxVerFileSize, Cache.Head().MaxDescFileSize) + 200)
f55ece0e
AL
39{
40}
41 /*}}}*/
42// RecordParser::Jump - Jump to a specific record /*{{{*/
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 /*}}}*/
2f6a2fbb
DK
52debRecordParser::~debRecordParser() {}
53
54// RecordParserBase::FileName - Return the archive filename on the site /*{{{*/
55string debRecordParserBase::FileName()
7e798dd7 56{
7974b907 57 return Section.FindS("Filename");
7e798dd7
AL
58}
59 /*}}}*/
2f6a2fbb
DK
60// RecordParserBase::Name - Return the package name /*{{{*/
61string debRecordParserBase::Name()
b2e465d6
AL
62{
63 return Section.FindS("Package");
64}
65 /*}}}*/
2f6a2fbb
DK
66// RecordParserBase::Homepage - Return the package homepage /*{{{*/
67string debRecordParserBase::Homepage()
f27b4a70
OS
68{
69 return Section.FindS("Homepage");
70}
71 /*}}}*/
2f6a2fbb
DK
72// RecordParserBase::Hashes - return the available archive hashes /*{{{*/
73HashStringList debRecordParserBase::Hashes() const
d9b9e9e2 74{
b3501edb
DK
75 HashStringList hashes;
76 for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type)
77 {
78 std::string const hash = Section.FindS(*type);
79 if (hash.empty() == false)
80 hashes.push_back(HashString(*type, hash));
81 }
82 return hashes;
d9b9e9e2
MV
83}
84 /*}}}*/
2f6a2fbb
DK
85// RecordParserBase::Maintainer - Return the maintainer email /*{{{*/
86string debRecordParserBase::Maintainer()
7e798dd7 87{
7974b907 88 return Section.FindS("Maintainer");
7e798dd7
AL
89}
90 /*}}}*/
2f6a2fbb
DK
91// RecordParserBase::RecordField - Return the value of an arbitrary field /*{{*/
92string debRecordParserBase::RecordField(const char *fieldName)
75bda619
MV
93{
94 return Section.FindS(fieldName);
95}
2f6a2fbb
DK
96 /*}}}*/
97// RecordParserBase::ShortDesc - Return a 1 line description /*{{{*/
98string debRecordParserBase::ShortDesc(std::string const &lang)
7e798dd7 99{
ffe3c68e
DK
100 string const Res = LongDesc(lang);
101 if (Res.empty() == true)
102 return "";
103 string::size_type const Pos = Res.find('\n');
7e798dd7
AL
104 if (Pos == string::npos)
105 return Res;
106 return string(Res,0,Pos);
107}
108 /*}}}*/
2f6a2fbb
DK
109// RecordParserBase::LongDesc - Return a longer description /*{{{*/
110string debRecordParserBase::LongDesc(std::string const &lang)
7e798dd7 111{
ffe3c68e
DK
112 string orig;
113 if (lang.empty() == true)
114 {
115 std::vector<string> const lang = APT::Configuration::getLanguages();
116 for (std::vector<string>::const_iterator l = lang.begin();
117 l != lang.end(); ++l)
118 {
119 std::string const tagname = "Description-" + *l;
120 orig = Section.FindS(tagname.c_str());
121 if (orig.empty() == false)
122 break;
123 else if (*l == "en")
124 {
125 orig = Section.FindS("Description");
126 if (orig.empty() == false)
127 break;
128 }
129 }
130 if (orig.empty() == true)
131 orig = Section.FindS("Description");
132 }
133 else
134 {
135 std::string const tagname = "Description-" + lang;
136 orig = Section.FindS(tagname.c_str());
137 if (orig.empty() == true && lang == "en")
138 orig = Section.FindS("Description");
139 }
a52f938b 140
ffe3c68e
DK
141 char const * const codeset = nl_langinfo(CODESET);
142 if (strcmp(codeset,"UTF-8") != 0) {
143 string dest;
144 UTF8ToCodeset(codeset, orig, &dest);
145 return dest;
146 }
a52f938b 147
a52f938b 148 return orig;
7e798dd7
AL
149}
150 /*}}}*/
c2f2b862 151
2f6a2fbb
DK
152static const char * const SourceVerSeparators = " ()";
153// RecordParserBase::SourcePkg - Return the source package name if any /*{{{*/
154string debRecordParserBase::SourcePkg()
36375005 155{
04f232fc 156 string Res = Section.FindS("Source");
c2f2b862 157 string::size_type Pos = Res.find_first_of(SourceVerSeparators);
04f232fc
AL
158 if (Pos == string::npos)
159 return Res;
160 return string(Res,0,Pos);
36375005
AL
161}
162 /*}}}*/
2f6a2fbb
DK
163// RecordParserBase::SourceVer - Return the source version number if present /*{{{*/
164string debRecordParserBase::SourceVer()
c2f2b862
MV
165{
166 string Pkg = Section.FindS("Source");
167 string::size_type Pos = Pkg.find_first_of(SourceVerSeparators);
168 if (Pos == string::npos)
169 return "";
170
171 string::size_type VerStart = Pkg.find_first_not_of(SourceVerSeparators, Pos);
172 if(VerStart == string::npos)
173 return "";
174
175 string::size_type VerEnd = Pkg.find_first_of(SourceVerSeparators, VerStart);
176 if(VerEnd == string::npos)
177 // Corresponds to the case of, e.g., "foo (1.2" without a closing
178 // paren. Be liberal and guess what it means.
179 return string(Pkg, VerStart);
180 else
181 return string(Pkg, VerStart, VerEnd - VerStart);
182}
183 /*}}}*/
2f6a2fbb
DK
184// RecordParserBase::GetRec - Return the whole record /*{{{*/
185void debRecordParserBase::GetRec(const char *&Start,const char *&Stop)
b2e465d6
AL
186{
187 Section.GetSection(Start,Stop);
188}
189 /*}}}*/
2f6a2fbb 190debRecordParserBase::~debRecordParserBase() {}
862bafea 191
2f6a2fbb
DK
192bool debDebFileRecordParser::LoadContent()
193{
194 // load content only once
195 if (controlContent.empty() == false)
196 return true;
197
198 std::ostringstream content;
199 if (debDebPkgFileIndex::GetContent(content, debFileName) == false)
200 return false;
201 // add two newlines to make sure the scanner finds the section,
202 // which is usually done by pkgTagFile automatically if needed.
203 content << "\n\n";
204
205 controlContent = content.str();
206 if (Section.Scan(controlContent.c_str(), controlContent.length()) == false)
207 return _error->Error(_("Unable to parse package file %s (%d)"), debFileName.c_str(), 3);
208 return true;
209}