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/error.h>
16 #include <apt-pkg/aptconfiguration.h>
20 // RecordParser::debRecordParser - Constructor /*{{{*/
21 // ---------------------------------------------------------------------
23 debRecordParser::debRecordParser(string FileName
,pkgCache
&Cache
) :
24 File(FileName
,FileFd::ReadOnlyGzip
),
25 Tags(&File
, std::max(Cache
.Head().MaxVerFileSize
,
26 Cache
.Head().MaxDescFileSize
) + 200)
30 // RecordParser::Jump - Jump to a specific record /*{{{*/
31 // ---------------------------------------------------------------------
33 bool debRecordParser::Jump(pkgCache::VerFileIterator
const &Ver
)
35 return Tags
.Jump(Section
,Ver
->Offset
);
37 bool debRecordParser::Jump(pkgCache::DescFileIterator
const &Desc
)
39 return Tags
.Jump(Section
,Desc
->Offset
);
42 // RecordParser::FileName - Return the archive filename on the site /*{{{*/
43 // ---------------------------------------------------------------------
45 string
debRecordParser::FileName()
47 return Section
.FindS("Filename");
50 // RecordParser::Name - Return the package name /*{{{*/
51 // ---------------------------------------------------------------------
53 string
debRecordParser::Name()
55 return Section
.FindS("Package");
58 // RecordParser::Homepage - Return the package homepage /*{{{*/
59 // ---------------------------------------------------------------------
61 string
debRecordParser::Homepage()
63 return Section
.FindS("Homepage");
66 // RecordParser::MD5Hash - Return the archive hash /*{{{*/
67 // ---------------------------------------------------------------------
69 string
debRecordParser::MD5Hash()
71 return Section
.FindS("MD5Sum");
74 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
75 // ---------------------------------------------------------------------
77 string
debRecordParser::SHA1Hash()
79 return Section
.FindS("SHA1");
82 // RecordParser::SHA256Hash - Return the archive hash /*{{{*/
83 // ---------------------------------------------------------------------
85 string
debRecordParser::SHA256Hash()
87 return Section
.FindS("SHA256");
90 // RecordParser::SHA512Hash - Return the archive hash /*{{{*/
91 // ---------------------------------------------------------------------
93 string
debRecordParser::SHA512Hash()
95 return Section
.FindS("SHA512");
98 // RecordParser::Maintainer - Return the maintainer email /*{{{*/
99 // ---------------------------------------------------------------------
101 string
debRecordParser::Maintainer()
103 return Section
.FindS("Maintainer");
106 // RecordParser::RecordField - Return the value of an arbitrary field /*{{*/
107 // ---------------------------------------------------------------------
109 string
debRecordParser::RecordField(const char *fieldName
)
111 return Section
.FindS(fieldName
);
115 // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
116 // ---------------------------------------------------------------------
118 string
debRecordParser::ShortDesc()
120 string Res
= LongDesc();
121 string::size_type Pos
= Res
.find('\n');
122 if (Pos
== string::npos
)
124 return string(Res
,0,Pos
);
127 // RecordParser::LongDesc - Return a longer description /*{{{*/
128 // ---------------------------------------------------------------------
130 string
debRecordParser::LongDesc()
134 if (!Section
.FindS("Description").empty())
135 orig
= Section
.FindS("Description").c_str();
138 vector
<string
> const lang
= APT::Configuration::getLanguages();
139 for (vector
<string
>::const_iterator l
= lang
.begin();
140 orig
.empty() && l
!= lang
.end(); ++l
)
141 orig
= Section
.FindS(string("Description-").append(*l
).c_str());
144 char const * const codeset
= nl_langinfo(CODESET
);
145 if (strcmp(codeset
,"UTF-8") != 0) {
146 UTF8ToCodeset(codeset
, orig
, &dest
);
154 static const char *SourceVerSeparators
= " ()";
156 // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
157 // ---------------------------------------------------------------------
159 string
debRecordParser::SourcePkg()
161 string Res
= Section
.FindS("Source");
162 string::size_type Pos
= Res
.find_first_of(SourceVerSeparators
);
163 if (Pos
== string::npos
)
165 return string(Res
,0,Pos
);
168 // RecordParser::SourceVer - Return the source version number if present /*{{{*/
169 // ---------------------------------------------------------------------
171 string
debRecordParser::SourceVer()
173 string Pkg
= Section
.FindS("Source");
174 string::size_type Pos
= Pkg
.find_first_of(SourceVerSeparators
);
175 if (Pos
== string::npos
)
178 string::size_type VerStart
= Pkg
.find_first_not_of(SourceVerSeparators
, Pos
);
179 if(VerStart
== string::npos
)
182 string::size_type VerEnd
= Pkg
.find_first_of(SourceVerSeparators
, VerStart
);
183 if(VerEnd
== string::npos
)
184 // Corresponds to the case of, e.g., "foo (1.2" without a closing
185 // paren. Be liberal and guess what it means.
186 return string(Pkg
, VerStart
);
188 return string(Pkg
, VerStart
, VerEnd
- VerStart
);
191 // RecordParser::GetRec - Return the whole record /*{{{*/
192 // ---------------------------------------------------------------------
194 void debRecordParser::GetRec(const char *&Start
,const char *&Stop
)
196 Section
.GetSection(Start
,Stop
);