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 if (!Section.FindS("Description").empty())
126 orig = Section.FindS("Description").c_str();
128 orig = Section.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str()).c_str();
130 if (strcmp(codeset,"UTF-8") != 0) {
131 UTF8ToCodeset(codeset, orig, &dest);
138 // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
139 // ---------------------------------------------------------------------
141 bool debRecordParser::ShortDesc(const char *&Start,const char *&End)
143 if (!LongDesc(Start,End))
145 const char *Line = (const char *) memchr(Start, '\n', End - Start);
151 // RecordParser::LongDesc - Return a longer description /*{{{*/
152 // ---------------------------------------------------------------------
154 bool debRecordParser::LongDesc(const char *&Start,const char *&End)
156 if (!Section.Find("Description",Start,End))
157 return Section.Find(("Description-" + pkgIndexFile::LanguageCode()).c_str(),Start,End);
162 static const char *SourceVerSeparators = " ()";
164 // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
165 // ---------------------------------------------------------------------
167 string debRecordParser::SourcePkg()
169 string Res = Section.FindS("Source");
170 string::size_type Pos = Res.find_first_of(SourceVerSeparators);
171 if (Pos == string::npos)
173 return string(Res,0,Pos);
176 // RecordParser::SourceVer - Return the source version number if present /*{{{*/
177 // ---------------------------------------------------------------------
179 string debRecordParser::SourceVer()
181 string Pkg = Section.FindS("Source");
182 string::size_type Pos = Pkg.find_first_of(SourceVerSeparators);
183 if (Pos == string::npos)
186 string::size_type VerStart = Pkg.find_first_not_of(SourceVerSeparators, Pos);
187 if(VerStart == string::npos)
190 string::size_type VerEnd = Pkg.find_first_of(SourceVerSeparators, VerStart);
191 if(VerEnd == string::npos)
192 // Corresponds to the case of, e.g., "foo (1.2" without a closing
193 // paren. Be liberal and guess what it means.
194 return string(Pkg, VerStart);
196 return string(Pkg, VerStart, VerEnd - VerStart);
199 // RecordParser::GetRec - Return the whole record /*{{{*/
200 // ---------------------------------------------------------------------
202 void debRecordParser::GetRec(const char *&Start,const char *&Stop)
204 Section.GetSection(Start,Stop);
207 // RecordParser::Find - Locate a tag /*{{{*/
208 // ---------------------------------------------------------------------
210 bool debRecordParser::Find(const char *Tag,const char *&Start, const char *&End)
212 return Section.Find(Tag,Start,End);