]>
git.saurik.com Git - apt.git/blob - apt-pkg/deb/debrecords.cc
ef6a7ca9d6ac547b8eef67693c792a06b0fe9953
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>
22 // RecordParser::debRecordParser - Constructor /*{{{*/
23 // ---------------------------------------------------------------------
25 debRecordParser::debRecordParser(string FileName
,pkgCache
&Cache
) :
26 File(FileName
,FileFd::ReadOnlyGzip
),
27 Tags(&File
, std::max(Cache
.Head().MaxVerFileSize
,
28 Cache
.Head().MaxDescFileSize
) + 200)
32 // RecordParser::Jump - Jump to a specific record /*{{{*/
33 // ---------------------------------------------------------------------
35 bool debRecordParser::Jump(pkgCache::VerFileIterator
const &Ver
)
37 return Tags
.Jump(Section
,Ver
->Offset
);
39 bool debRecordParser::Jump(pkgCache::DescFileIterator
const &Desc
)
41 return Tags
.Jump(Section
,Desc
->Offset
);
44 // RecordParser::FileName - Return the archive filename on the site /*{{{*/
45 // ---------------------------------------------------------------------
47 string
debRecordParser::FileName()
49 return Section
.FindS("Filename");
52 // RecordParser::Name - Return the package name /*{{{*/
53 // ---------------------------------------------------------------------
55 string
debRecordParser::Name()
57 return Section
.FindS("Package");
60 // RecordParser::Homepage - Return the package homepage /*{{{*/
61 // ---------------------------------------------------------------------
63 string
debRecordParser::Homepage()
65 return Section
.FindS("Homepage");
68 // RecordParser::MD5Hash - Return the archive hash /*{{{*/
69 // ---------------------------------------------------------------------
71 string
debRecordParser::MD5Hash()
73 return Section
.FindS("MD5Sum");
76 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
77 // ---------------------------------------------------------------------
79 string
debRecordParser::SHA1Hash()
81 return Section
.FindS("SHA1");
84 // RecordParser::SHA256Hash - Return the archive hash /*{{{*/
85 // ---------------------------------------------------------------------
87 string
debRecordParser::SHA256Hash()
89 return Section
.FindS("SHA256");
92 // RecordParser::SHA512Hash - Return the archive hash /*{{{*/
93 // ---------------------------------------------------------------------
95 string
debRecordParser::SHA512Hash()
97 return Section
.FindS("SHA512");
100 // RecordParser::Maintainer - Return the maintainer email /*{{{*/
101 // ---------------------------------------------------------------------
103 string
debRecordParser::Maintainer()
105 return Section
.FindS("Maintainer");
108 // RecordParser::RecordField - Return the value of an arbitrary field /*{{*/
109 // ---------------------------------------------------------------------
111 string
debRecordParser::RecordField(const char *fieldName
)
113 return Section
.FindS(fieldName
);
117 // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
118 // ---------------------------------------------------------------------
120 string
debRecordParser::ShortDesc()
122 string Res
= LongDesc();
123 string::size_type Pos
= Res
.find('\n');
124 if (Pos
== string::npos
)
126 return string(Res
,0,Pos
);
129 // RecordParser::LongDesc - Return a longer description /*{{{*/
130 // ---------------------------------------------------------------------
132 string
debRecordParser::LongDesc()
136 if (!Section
.FindS("Description").empty())
137 orig
= Section
.FindS("Description").c_str();
140 std::vector
<string
> const lang
= APT::Configuration::getLanguages();
141 for (std::vector
<string
>::const_iterator l
= lang
.begin();
142 orig
.empty() && l
!= lang
.end(); ++l
)
143 orig
= Section
.FindS(string("Description-").append(*l
).c_str());
146 char const * const codeset
= nl_langinfo(CODESET
);
147 if (strcmp(codeset
,"UTF-8") != 0) {
148 UTF8ToCodeset(codeset
, orig
, &dest
);
156 static const char *SourceVerSeparators
= " ()";
158 // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
159 // ---------------------------------------------------------------------
161 string
debRecordParser::SourcePkg()
163 string Res
= Section
.FindS("Source");
164 string::size_type Pos
= Res
.find_first_of(SourceVerSeparators
);
165 if (Pos
== string::npos
)
167 return string(Res
,0,Pos
);
170 // RecordParser::SourceVer - Return the source version number if present /*{{{*/
171 // ---------------------------------------------------------------------
173 string
debRecordParser::SourceVer()
175 string Pkg
= Section
.FindS("Source");
176 string::size_type Pos
= Pkg
.find_first_of(SourceVerSeparators
);
177 if (Pos
== string::npos
)
180 string::size_type VerStart
= Pkg
.find_first_not_of(SourceVerSeparators
, Pos
);
181 if(VerStart
== string::npos
)
184 string::size_type VerEnd
= Pkg
.find_first_of(SourceVerSeparators
, VerStart
);
185 if(VerEnd
== string::npos
)
186 // Corresponds to the case of, e.g., "foo (1.2" without a closing
187 // paren. Be liberal and guess what it means.
188 return string(Pkg
, VerStart
);
190 return string(Pkg
, VerStart
, VerEnd
- VerStart
);
193 // RecordParser::GetRec - Return the whole record /*{{{*/
194 // ---------------------------------------------------------------------
196 void debRecordParser::GetRec(const char *&Start
,const char *&Stop
)
198 Section
.GetSection(Start
,Stop
);