]>
git.saurik.com Git - apt-legacy.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 /*{{{*/
11 #include <apt-pkg/debrecords.h>
12 #include <apt-pkg/strutl.h>
13 #include <apt-pkg/error.h>
17 // RecordParser::debRecordParser - Constructor /*{{{*/
18 // ---------------------------------------------------------------------
20 debRecordParser::debRecordParser(string FileName
,pkgCache
&Cache
) :
21 File(FileName
,FileFd::ReadOnly
),
22 Tags(&File
,Cache
.Head().MaxVerFileSize
+ 200)
26 // RecordParser::Jump - Jump to a specific record /*{{{*/
27 // ---------------------------------------------------------------------
29 bool debRecordParser::Jump(pkgCache::VerFileIterator
const &Ver
)
31 return Tags
.Jump(Section
,Ver
->Offset
);
33 bool debRecordParser::Jump(pkgCache::DescFileIterator
const &Desc
)
35 return Tags
.Jump(Section
,Desc
->Offset
);
38 // RecordParser::FileName - Return the archive filename on the site /*{{{*/
39 // ---------------------------------------------------------------------
41 string
debRecordParser::FileName()
43 return Section
.FindS("Filename");
46 // RecordParser::Name - Return the package name /*{{{*/
47 // ---------------------------------------------------------------------
49 string
debRecordParser::Name()
51 return Section
.FindS("Package");
54 // RecordParser::Display - Return the package display name /*{{{*/
55 // ---------------------------------------------------------------------
57 string
debRecordParser::Display()
59 string
display(Section
.FindS("Name"));
61 display
= Section
.FindS("Maemo-Display-Name");
65 // RecordParser::Homepage - Return the package homepage /*{{{*/
66 // ---------------------------------------------------------------------
68 string
debRecordParser::Homepage()
70 return Section
.FindS("Homepage");
73 // RecordParser::MD5Hash - Return the archive hash /*{{{*/
74 // ---------------------------------------------------------------------
76 string
debRecordParser::MD5Hash()
78 return Section
.FindS("MD5Sum");
81 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
82 // ---------------------------------------------------------------------
84 string
debRecordParser::SHA1Hash()
86 return Section
.FindS("SHA1");
89 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
90 // ---------------------------------------------------------------------
92 string
debRecordParser::SHA256Hash()
94 return Section
.FindS("SHA256");
97 // RecordParser::Maintainer - Return the maintainer email /*{{{*/
98 // ---------------------------------------------------------------------
100 string
debRecordParser::Maintainer()
102 return Section
.FindS("Maintainer");
105 // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
106 // ---------------------------------------------------------------------
108 string
debRecordParser::ShortDesc()
110 string Res
= LongDesc();
111 string::size_type Pos
= Res
.find('\n');
112 if (Pos
== string::npos
)
114 return string(Res
,0,Pos
);
117 // RecordParser::LongDesc - Return a longer description /*{{{*/
118 // ---------------------------------------------------------------------
120 string
debRecordParser::LongDesc()
123 char *codeset
= nl_langinfo(CODESET
);
125 orig
= Section
.FindS("Description");
127 orig
= Section
.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str());
129 if (strcmp(codeset
,"UTF-8") != 0) {
130 UTF8ToCodeset(codeset
, orig
, &dest
);
137 // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
138 // ---------------------------------------------------------------------
140 bool debRecordParser::ShortDesc(const char *&Start
,const char *&End
)
142 if (!LongDesc(Start
,End
))
144 const char *Line
= (const char *) memchr(Start
, '\n', End
- Start
);
150 // RecordParser::LongDesc - Return a longer description /*{{{*/
151 // ---------------------------------------------------------------------
153 bool debRecordParser::LongDesc(const char *&Start
,const char *&End
)
155 if (!Section
.Find("Description",Start
,End
))
156 return Section
.Find(("Description-" + pkgIndexFile::LanguageCode()).c_str(),Start
,End
);
161 static const char *SourceVerSeparators
= " ()";
163 // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
164 // ---------------------------------------------------------------------
166 string
debRecordParser::SourcePkg()
168 string Res
= Section
.FindS("Source");
169 string::size_type Pos
= Res
.find_first_of(SourceVerSeparators
);
170 if (Pos
== string::npos
)
172 return string(Res
,0,Pos
);
175 // RecordParser::SourceVer - Return the source version number if present /*{{{*/
176 // ---------------------------------------------------------------------
178 string
debRecordParser::SourceVer()
180 string Pkg
= Section
.FindS("Source");
181 string::size_type Pos
= Pkg
.find_first_of(SourceVerSeparators
);
182 if (Pos
== string::npos
)
185 string::size_type VerStart
= Pkg
.find_first_not_of(SourceVerSeparators
, Pos
);
186 if(VerStart
== string::npos
)
189 string::size_type VerEnd
= Pkg
.find_first_of(SourceVerSeparators
, VerStart
);
190 if(VerEnd
== string::npos
)
191 // Corresponds to the case of, e.g., "foo (1.2" without a closing
192 // paren. Be liberal and guess what it means.
193 return string(Pkg
, VerStart
);
195 return string(Pkg
, VerStart
, VerEnd
- VerStart
);
198 // RecordParser::GetRec - Return the whole record /*{{{*/
199 // ---------------------------------------------------------------------
201 void debRecordParser::GetRec(const char *&Start
,const char *&Stop
)
203 Section
.GetSection(Start
,Stop
);
206 // RecordParser::Find - Locate a tag /*{{{*/
207 // ---------------------------------------------------------------------
209 bool debRecordParser::Find(const char *Tag
,const char *&Start
, const char *&End
)
211 return Section
.Find(Tag
,Start
,End
);