]>
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/error.h>
16 #include <apt-pkg/aptconfiguration.h>
17 #include <apt-pkg/fileutl.h>
24 // RecordParser::debRecordParser - Constructor /*{{{*/
25 // ---------------------------------------------------------------------
27 debRecordParser::debRecordParser(string FileName
,pkgCache
&Cache
) :
28 File(FileName
,FileFd::ReadOnlyGzip
),
29 Tags(&File
, std::max(Cache
.Head().MaxVerFileSize
,
30 Cache
.Head().MaxDescFileSize
) + 200)
34 // RecordParser::Jump - Jump to a specific record /*{{{*/
35 // ---------------------------------------------------------------------
37 bool debRecordParser::Jump(pkgCache::VerFileIterator
const &Ver
)
39 return Tags
.Jump(Section
,Ver
->Offset
);
41 bool debRecordParser::Jump(pkgCache::DescFileIterator
const &Desc
)
43 return Tags
.Jump(Section
,Desc
->Offset
);
46 // RecordParser::FileName - Return the archive filename on the site /*{{{*/
47 // ---------------------------------------------------------------------
49 string
debRecordParser::FileName()
51 return Section
.FindS("Filename");
54 // RecordParser::Name - Return the package name /*{{{*/
55 // ---------------------------------------------------------------------
57 string
debRecordParser::Name()
59 return Section
.FindS("Package");
62 // RecordParser::Homepage - Return the package homepage /*{{{*/
63 // ---------------------------------------------------------------------
65 string
debRecordParser::Homepage()
67 return Section
.FindS("Homepage");
70 // RecordParser::MD5Hash - Return the archive hash /*{{{*/
71 // ---------------------------------------------------------------------
73 string
debRecordParser::MD5Hash()
75 return Section
.FindS("MD5Sum");
78 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
79 // ---------------------------------------------------------------------
81 string
debRecordParser::SHA1Hash()
83 return Section
.FindS("SHA1");
86 // RecordParser::SHA256Hash - Return the archive hash /*{{{*/
87 // ---------------------------------------------------------------------
89 string
debRecordParser::SHA256Hash()
91 return Section
.FindS("SHA256");
94 // RecordParser::SHA512Hash - Return the archive hash /*{{{*/
95 // ---------------------------------------------------------------------
97 string
debRecordParser::SHA512Hash()
99 return Section
.FindS("SHA512");
102 // RecordParser::Maintainer - Return the maintainer email /*{{{*/
103 // ---------------------------------------------------------------------
105 string
debRecordParser::Maintainer()
107 return Section
.FindS("Maintainer");
110 // RecordParser::RecordField - Return the value of an arbitrary field /*{{*/
111 // ---------------------------------------------------------------------
113 string
debRecordParser::RecordField(const char *fieldName
)
115 return Section
.FindS(fieldName
);
119 // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
120 // ---------------------------------------------------------------------
122 string
debRecordParser::ShortDesc()
124 string Res
= LongDesc();
125 string::size_type Pos
= Res
.find('\n');
126 if (Pos
== string::npos
)
128 return string(Res
,0,Pos
);
131 // RecordParser::LongDesc - Return a longer description /*{{{*/
132 // ---------------------------------------------------------------------
134 string
debRecordParser::LongDesc()
138 if (!Section
.FindS("Description").empty())
139 orig
= Section
.FindS("Description").c_str();
142 std::vector
<string
> const lang
= APT::Configuration::getLanguages();
143 for (std::vector
<string
>::const_iterator l
= lang
.begin();
144 orig
.empty() && l
!= lang
.end(); ++l
)
145 orig
= Section
.FindS(string("Description-").append(*l
).c_str());
148 char const * const codeset
= nl_langinfo(CODESET
);
149 if (strcmp(codeset
,"UTF-8") != 0) {
150 UTF8ToCodeset(codeset
, orig
, &dest
);
158 static const char *SourceVerSeparators
= " ()";
160 // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
161 // ---------------------------------------------------------------------
163 string
debRecordParser::SourcePkg()
165 string Res
= Section
.FindS("Source");
166 string::size_type Pos
= Res
.find_first_of(SourceVerSeparators
);
167 if (Pos
== string::npos
)
169 return string(Res
,0,Pos
);
172 // RecordParser::SourceVer - Return the source version number if present /*{{{*/
173 // ---------------------------------------------------------------------
175 string
debRecordParser::SourceVer()
177 string Pkg
= Section
.FindS("Source");
178 string::size_type Pos
= Pkg
.find_first_of(SourceVerSeparators
);
179 if (Pos
== string::npos
)
182 string::size_type VerStart
= Pkg
.find_first_not_of(SourceVerSeparators
, Pos
);
183 if(VerStart
== string::npos
)
186 string::size_type VerEnd
= Pkg
.find_first_of(SourceVerSeparators
, VerStart
);
187 if(VerEnd
== string::npos
)
188 // Corresponds to the case of, e.g., "foo (1.2" without a closing
189 // paren. Be liberal and guess what it means.
190 return string(Pkg
, VerStart
);
192 return string(Pkg
, VerStart
, VerEnd
- VerStart
);
195 // RecordParser::GetRec - Return the whole record /*{{{*/
196 // ---------------------------------------------------------------------
198 void debRecordParser::GetRec(const char *&Start
,const char *&Stop
)
200 Section
.GetSection(Start
,Stop
);