]>
git.saurik.com Git - apt.git/blob - apt-pkg/deb/debrecords.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: debrecords.cc,v 1.10 2001/03/13 06:51:46 jgg Exp $
4 /* ######################################################################
6 Debian Package Records - Parser for debian package records
8 ##################################################################### */
10 // Include Files /*{{{*/
13 #include <apt-pkg/debrecords.h>
14 #include <apt-pkg/debindexfile.h>
15 #include <apt-pkg/strutl.h>
16 #include <apt-pkg/aptconfiguration.h>
17 #include <apt-pkg/fileutl.h>
18 #include <apt-pkg/cacheiterators.h>
19 #include <apt-pkg/pkgcache.h>
20 #include <apt-pkg/tagfile.h>
21 #include <apt-pkg/error.h>
35 // RecordParser::debRecordParser - Constructor /*{{{*/
36 debRecordParser::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)
42 // RecordParser::Jump - Jump to a specific record /*{{{*/
43 bool debRecordParser::Jump(pkgCache::VerFileIterator
const &Ver
)
45 return Tags
.Jump(Section
,Ver
->Offset
);
47 bool debRecordParser::Jump(pkgCache::DescFileIterator
const &Desc
)
49 return Tags
.Jump(Section
,Desc
->Offset
);
52 debRecordParser::~debRecordParser() {}
54 // RecordParserBase::FileName - Return the archive filename on the site /*{{{*/
55 string
debRecordParserBase::FileName()
57 return Section
.FindS("Filename");
60 // RecordParserBase::Name - Return the package name /*{{{*/
61 string
debRecordParserBase::Name()
63 return Section
.FindS("Package");
66 // RecordParserBase::Homepage - Return the package homepage /*{{{*/
67 string
debRecordParserBase::Homepage()
69 return Section
.FindS("Homepage");
72 // RecordParserBase::Hashes - return the available archive hashes /*{{{*/
73 HashStringList
debRecordParserBase::Hashes() const
75 HashStringList hashes
;
76 for (char const * const * type
= HashString::SupportedHashes(); *type
!= NULL
; ++type
)
78 std::string
const hash
= Section
.FindS(*type
);
79 if (hash
.empty() == false)
80 hashes
.push_back(HashString(*type
, hash
));
85 // RecordParserBase::Maintainer - Return the maintainer email /*{{{*/
86 string
debRecordParserBase::Maintainer()
88 return Section
.FindS("Maintainer");
91 // RecordParserBase::RecordField - Return the value of an arbitrary field /*{{*/
92 string
debRecordParserBase::RecordField(const char *fieldName
)
94 return Section
.FindS(fieldName
);
97 // RecordParserBase::ShortDesc - Return a 1 line description /*{{{*/
98 string
debRecordParserBase::ShortDesc(std::string
const &lang
)
100 string
const Res
= LongDesc(lang
);
101 if (Res
.empty() == true)
103 string::size_type
const Pos
= Res
.find('\n');
104 if (Pos
== string::npos
)
106 return string(Res
,0,Pos
);
109 // RecordParserBase::LongDesc - Return a longer description /*{{{*/
110 string
debRecordParserBase::LongDesc(std::string
const &lang
)
113 if (lang
.empty() == true)
115 std::vector
<string
> const lang
= APT::Configuration::getLanguages();
116 for (std::vector
<string
>::const_iterator l
= lang
.begin();
117 l
!= lang
.end(); ++l
)
119 std::string
const tagname
= "Description-" + *l
;
120 orig
= Section
.FindS(tagname
.c_str());
121 if (orig
.empty() == false)
125 orig
= Section
.FindS("Description");
126 if (orig
.empty() == false)
130 if (orig
.empty() == true)
131 orig
= Section
.FindS("Description");
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");
141 char const * const codeset
= nl_langinfo(CODESET
);
142 if (strcmp(codeset
,"UTF-8") != 0) {
144 UTF8ToCodeset(codeset
, orig
, &dest
);
152 static const char * const SourceVerSeparators
= " ()";
153 // RecordParserBase::SourcePkg - Return the source package name if any /*{{{*/
154 string
debRecordParserBase::SourcePkg()
156 string Res
= Section
.FindS("Source");
157 string::size_type Pos
= Res
.find_first_of(SourceVerSeparators
);
158 if (Pos
== string::npos
)
160 return string(Res
,0,Pos
);
163 // RecordParserBase::SourceVer - Return the source version number if present /*{{{*/
164 string
debRecordParserBase::SourceVer()
166 string Pkg
= Section
.FindS("Source");
167 string::size_type Pos
= Pkg
.find_first_of(SourceVerSeparators
);
168 if (Pos
== string::npos
)
171 string::size_type VerStart
= Pkg
.find_first_not_of(SourceVerSeparators
, Pos
);
172 if(VerStart
== string::npos
)
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
);
181 return string(Pkg
, VerStart
, VerEnd
- VerStart
);
184 // RecordParserBase::GetRec - Return the whole record /*{{{*/
185 void debRecordParserBase::GetRec(const char *&Start
,const char *&Stop
)
187 Section
.GetSection(Start
,Stop
);
190 debRecordParserBase::~debRecordParserBase() {}
192 bool debDebFileRecordParser::LoadContent()
194 // load content only once
195 if (controlContent
.empty() == false)
198 std::ostringstream content
;
199 if (debDebPkgFileIndex::GetContent(content
, debFileName
) == false)
201 // add two newlines to make sure the scanner finds the section,
202 // which is usually done by pkgTagFile automatically if needed.
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);