]> git.saurik.com Git - apt-legacy.git/blob - apt-pkg/deb/debrecords.cc
Numerous fundamental performance improvements for APT.
[apt-legacy.git] / apt-pkg / deb / debrecords.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: debrecords.cc,v 1.10 2001/03/13 06:51:46 jgg Exp $
4 /* ######################################################################
5
6 Debian Package Records - Parser for debian package records
7
8 ##################################################################### */
9 /*}}}*/
10 // Include Files /*{{{*/
11 #include <apt-pkg/debrecords.h>
12 #include <apt-pkg/strutl.h>
13 #include <apt-pkg/error.h>
14 #include <langinfo.h>
15 /*}}}*/
16
17 // RecordParser::debRecordParser - Constructor /*{{{*/
18 // ---------------------------------------------------------------------
19 /* */
20 debRecordParser::debRecordParser(string FileName,pkgCache &Cache) :
21 File(FileName,FileFd::ReadOnly),
22 Tags(&File,Cache.Head().MaxVerFileSize + 200)
23 {
24 }
25 /*}}}*/
26 // RecordParser::Jump - Jump to a specific record /*{{{*/
27 // ---------------------------------------------------------------------
28 /* */
29 bool debRecordParser::Jump(pkgCache::VerFileIterator const &Ver)
30 {
31 return Tags.Jump(Section,Ver->Offset);
32 }
33 bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc)
34 {
35 return Tags.Jump(Section,Desc->Offset);
36 }
37 /*}}}*/
38 // RecordParser::FileName - Return the archive filename on the site /*{{{*/
39 // ---------------------------------------------------------------------
40 /* */
41 string debRecordParser::FileName()
42 {
43 return Section.FindS("Filename");
44 }
45 /*}}}*/
46 // RecordParser::Name - Return the package name /*{{{*/
47 // ---------------------------------------------------------------------
48 /* */
49 string debRecordParser::Name()
50 {
51 return Section.FindS("Package");
52 }
53 /*}}}*/
54 // RecordParser::Display - Return the package display name /*{{{*/
55 // ---------------------------------------------------------------------
56 /* */
57 string debRecordParser::Display()
58 {
59 string display(Section.FindS("Name"));
60 if (display.empty())
61 display = Section.FindS("Maemo-Display-Name");
62 return display;
63 }
64 /*}}}*/
65 // RecordParser::Homepage - Return the package homepage /*{{{*/
66 // ---------------------------------------------------------------------
67 /* */
68 string debRecordParser::Homepage()
69 {
70 return Section.FindS("Homepage");
71 }
72 /*}}}*/
73 // RecordParser::MD5Hash - Return the archive hash /*{{{*/
74 // ---------------------------------------------------------------------
75 /* */
76 string debRecordParser::MD5Hash()
77 {
78 return Section.FindS("MD5Sum");
79 }
80 /*}}}*/
81 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
82 // ---------------------------------------------------------------------
83 /* */
84 string debRecordParser::SHA1Hash()
85 {
86 return Section.FindS("SHA1");
87 }
88 /*}}}*/
89 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
90 // ---------------------------------------------------------------------
91 /* */
92 string debRecordParser::SHA256Hash()
93 {
94 return Section.FindS("SHA256");
95 }
96 /*}}}*/
97 // RecordParser::Maintainer - Return the maintainer email /*{{{*/
98 // ---------------------------------------------------------------------
99 /* */
100 string debRecordParser::Maintainer()
101 {
102 return Section.FindS("Maintainer");
103 }
104 /*}}}*/
105 // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
106 // ---------------------------------------------------------------------
107 /* */
108 string debRecordParser::ShortDesc()
109 {
110 string Res = LongDesc();
111 string::size_type Pos = Res.find('\n');
112 if (Pos == string::npos)
113 return Res;
114 return string(Res,0,Pos);
115 }
116 /*}}}*/
117 // RecordParser::LongDesc - Return a longer description /*{{{*/
118 // ---------------------------------------------------------------------
119 /* */
120 string debRecordParser::LongDesc()
121 {
122 string orig, dest;
123 char *codeset = nl_langinfo(CODESET);
124
125 orig = Section.FindS("Description");
126 if (orig.empty())
127 orig = Section.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str());
128
129 if (strcmp(codeset,"UTF-8") != 0) {
130 UTF8ToCodeset(codeset, orig, &dest);
131 orig = dest;
132 }
133
134 return orig;
135 }
136 /*}}}*/
137 // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
138 // ---------------------------------------------------------------------
139 /* */
140 bool debRecordParser::ShortDesc(const char *&Start,const char *&End)
141 {
142 if (!LongDesc(Start,End))
143 return false;
144 const char *Line = (const char *) memchr(Start, '\n', End - Start);
145 if (Line != NULL)
146 End = Line;
147 return true;
148 }
149 /*}}}*/
150 // RecordParser::LongDesc - Return a longer description /*{{{*/
151 // ---------------------------------------------------------------------
152 /* */
153 bool debRecordParser::LongDesc(const char *&Start,const char *&End)
154 {
155 if (!Section.Find("Description",Start,End))
156 return Section.Find(("Description-" + pkgIndexFile::LanguageCode()).c_str(),Start,End);
157 return true;
158 }
159 /*}}}*/
160
161 static const char *SourceVerSeparators = " ()";
162
163 // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
164 // ---------------------------------------------------------------------
165 /* */
166 string debRecordParser::SourcePkg()
167 {
168 string Res = Section.FindS("Source");
169 string::size_type Pos = Res.find_first_of(SourceVerSeparators);
170 if (Pos == string::npos)
171 return Res;
172 return string(Res,0,Pos);
173 }
174 /*}}}*/
175 // RecordParser::SourceVer - Return the source version number if present /*{{{*/
176 // ---------------------------------------------------------------------
177 /* */
178 string debRecordParser::SourceVer()
179 {
180 string Pkg = Section.FindS("Source");
181 string::size_type Pos = Pkg.find_first_of(SourceVerSeparators);
182 if (Pos == string::npos)
183 return "";
184
185 string::size_type VerStart = Pkg.find_first_not_of(SourceVerSeparators, Pos);
186 if(VerStart == string::npos)
187 return "";
188
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);
194 else
195 return string(Pkg, VerStart, VerEnd - VerStart);
196 }
197 /*}}}*/
198 // RecordParser::GetRec - Return the whole record /*{{{*/
199 // ---------------------------------------------------------------------
200 /* */
201 void debRecordParser::GetRec(const char *&Start,const char *&Stop)
202 {
203 Section.GetSection(Start,Stop);
204 }
205 /*}}}*/
206 // RecordParser::Find - Locate a tag /*{{{*/
207 // ---------------------------------------------------------------------
208 /* */
209 bool debRecordParser::Find(const char *Tag,const char *&Start, const char *&End)
210 {
211 return Section.Find(Tag,Start,End);
212 }
213 /*}}}*/