]>
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::MD5Hash - Return the archive hash /*{{{*/
77 // ---------------------------------------------------------------------
79 string
debRecordParser::MD5Hash()
81 return Section
.FindS("MD5Sum");
84 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
85 // ---------------------------------------------------------------------
87 string
debRecordParser::SHA1Hash()
89 return Section
.FindS("SHA1");
92 // RecordParser::SHA256Hash - Return the archive hash /*{{{*/
93 // ---------------------------------------------------------------------
95 string
debRecordParser::SHA256Hash()
97 return Section
.FindS("SHA256");
100 // RecordParser::SHA512Hash - Return the archive hash /*{{{*/
101 // ---------------------------------------------------------------------
103 string
debRecordParser::SHA512Hash()
105 return Section
.FindS("SHA512");
108 // RecordParser::Maintainer - Return the maintainer email /*{{{*/
109 // ---------------------------------------------------------------------
111 string
debRecordParser::Maintainer()
113 return Section
.FindS("Maintainer");
116 // RecordParser::RecordField - Return the value of an arbitrary field /*{{*/
117 // ---------------------------------------------------------------------
119 string
debRecordParser::RecordField(const char *fieldName
)
121 return Section
.FindS(fieldName
);
125 // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
126 // ---------------------------------------------------------------------
128 string
debRecordParser::ShortDesc()
130 string Res
= LongDesc();
131 string::size_type Pos
= Res
.find('\n');
132 if (Pos
== string::npos
)
134 return string(Res
,0,Pos
);
137 // RecordParser::LongDesc - Return a longer description /*{{{*/
138 // ---------------------------------------------------------------------
140 string
debRecordParser::LongDesc()
144 if (!Section
.FindS("Description").empty())
145 orig
= Section
.FindS("Description").c_str();
148 std::vector
<string
> const lang
= APT::Configuration::getLanguages();
149 for (std::vector
<string
>::const_iterator l
= lang
.begin();
150 orig
.empty() && l
!= lang
.end(); ++l
)
151 orig
= Section
.FindS(string("Description-").append(*l
).c_str());
154 char const * const codeset
= nl_langinfo(CODESET
);
155 if (strcmp(codeset
,"UTF-8") != 0) {
156 UTF8ToCodeset(codeset
, orig
, &dest
);
164 static const char *SourceVerSeparators
= " ()";
166 // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
167 // ---------------------------------------------------------------------
169 string
debRecordParser::SourcePkg()
171 string Res
= Section
.FindS("Source");
172 string::size_type Pos
= Res
.find_first_of(SourceVerSeparators
);
173 if (Pos
== string::npos
)
175 return string(Res
,0,Pos
);
178 // RecordParser::SourceVer - Return the source version number if present /*{{{*/
179 // ---------------------------------------------------------------------
181 string
debRecordParser::SourceVer()
183 string Pkg
= Section
.FindS("Source");
184 string::size_type Pos
= Pkg
.find_first_of(SourceVerSeparators
);
185 if (Pos
== string::npos
)
188 string::size_type VerStart
= Pkg
.find_first_not_of(SourceVerSeparators
, Pos
);
189 if(VerStart
== string::npos
)
192 string::size_type VerEnd
= Pkg
.find_first_of(SourceVerSeparators
, VerStart
);
193 if(VerEnd
== string::npos
)
194 // Corresponds to the case of, e.g., "foo (1.2" without a closing
195 // paren. Be liberal and guess what it means.
196 return string(Pkg
, VerStart
);
198 return string(Pkg
, VerStart
, VerEnd
- VerStart
);
201 // RecordParser::GetRec - Return the whole record /*{{{*/
202 // ---------------------------------------------------------------------
204 void debRecordParser::GetRec(const char *&Start
,const char *&Stop
)
206 Section
.GetSection(Start
,Stop
);