]>
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/strutl.h>
15 #include <apt-pkg/aptconfiguration.h>
16 #include <apt-pkg/fileutl.h>
17 #include <apt-pkg/cacheiterators.h>
18 #include <apt-pkg/pkgcache.h>
19 #include <apt-pkg/tagfile.h>
30 // RecordParser::debRecordParser - Constructor /*{{{*/
31 // ---------------------------------------------------------------------
33 debRecordParser::debRecordParser(string FileName
,pkgCache
&Cache
) :
34 File(FileName
,FileFd::ReadOnly
, FileFd::Extension
),
35 Tags(&File
, std::max(Cache
.Head().MaxVerFileSize
,
36 Cache
.Head().MaxDescFileSize
) + 200)
40 // RecordParser::Jump - Jump to a specific record /*{{{*/
41 // ---------------------------------------------------------------------
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 // RecordParser::FileName - Return the archive filename on the site /*{{{*/
53 // ---------------------------------------------------------------------
55 string
debRecordParser::FileName()
57 return Section
.FindS("Filename");
60 // RecordParser::Name - Return the package name /*{{{*/
61 // ---------------------------------------------------------------------
63 string
debRecordParser::Name()
65 return Section
.FindS("Package");
68 // RecordParser::Homepage - Return the package homepage /*{{{*/
69 // ---------------------------------------------------------------------
71 string
debRecordParser::Homepage()
73 return Section
.FindS("Homepage");
76 // RecordParser::Hashes - return the available archive hashes /*{{{*/
77 HashStringList
debRecordParser::Hashes() const
79 HashStringList hashes
;
80 for (char const * const * type
= HashString::SupportedHashes(); *type
!= NULL
; ++type
)
82 std::string
const hash
= Section
.FindS(*type
);
83 if (hash
.empty() == false)
84 hashes
.push_back(HashString(*type
, hash
));
89 // RecordParser::Maintainer - Return the maintainer email /*{{{*/
90 // ---------------------------------------------------------------------
92 string
debRecordParser::Maintainer()
94 return Section
.FindS("Maintainer");
97 // RecordParser::RecordField - Return the value of an arbitrary field /*{{*/
98 // ---------------------------------------------------------------------
100 string
debRecordParser::RecordField(const char *fieldName
)
102 return Section
.FindS(fieldName
);
106 // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
107 // ---------------------------------------------------------------------
109 string
debRecordParser::ShortDesc(std::string
const &lang
)
111 string
const Res
= LongDesc(lang
);
112 if (Res
.empty() == true)
114 string::size_type
const Pos
= Res
.find('\n');
115 if (Pos
== string::npos
)
117 return string(Res
,0,Pos
);
120 // RecordParser::LongDesc - Return a longer description /*{{{*/
121 // ---------------------------------------------------------------------
123 string
debRecordParser::LongDesc(std::string
const &lang
)
126 if (lang
.empty() == true)
128 std::vector
<string
> const lang
= APT::Configuration::getLanguages();
129 for (std::vector
<string
>::const_iterator l
= lang
.begin();
130 l
!= lang
.end(); ++l
)
132 std::string
const tagname
= "Description-" + *l
;
133 orig
= Section
.FindS(tagname
.c_str());
134 if (orig
.empty() == false)
138 orig
= Section
.FindS("Description");
139 if (orig
.empty() == false)
143 if (orig
.empty() == true)
144 orig
= Section
.FindS("Description");
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");
154 char const * const codeset
= nl_langinfo(CODESET
);
155 if (strcmp(codeset
,"UTF-8") != 0) {
157 UTF8ToCodeset(codeset
, orig
, &dest
);
165 static const char *SourceVerSeparators
= " ()";
167 // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
168 // ---------------------------------------------------------------------
170 string
debRecordParser::SourcePkg()
172 string Res
= Section
.FindS("Source");
173 string::size_type Pos
= Res
.find_first_of(SourceVerSeparators
);
174 if (Pos
== string::npos
)
176 return string(Res
,0,Pos
);
179 // RecordParser::SourceVer - Return the source version number if present /*{{{*/
180 // ---------------------------------------------------------------------
182 string
debRecordParser::SourceVer()
184 string Pkg
= Section
.FindS("Source");
185 string::size_type Pos
= Pkg
.find_first_of(SourceVerSeparators
);
186 if (Pos
== string::npos
)
189 string::size_type VerStart
= Pkg
.find_first_not_of(SourceVerSeparators
, Pos
);
190 if(VerStart
== string::npos
)
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
);
199 return string(Pkg
, VerStart
, VerEnd
- VerStart
);
202 // RecordParser::GetRec - Return the whole record /*{{{*/
203 // ---------------------------------------------------------------------
205 void debRecordParser::GetRec(const char *&Start
,const char *&Stop
)
207 Section
.GetSection(Start
,Stop
);
211 debRecordParser::~debRecordParser() {}