]>
Commit | Line | Data |
---|---|---|
acdafb44 JF |
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 | if (!Section.FindS("Description").empty()) | |
126 | orig = Section.FindS("Description").c_str(); | |
127 | else | |
128 | orig = Section.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str()).c_str(); | |
129 | ||
130 | if (strcmp(codeset,"UTF-8") != 0) { | |
131 | UTF8ToCodeset(codeset, orig, &dest); | |
132 | orig = dest; | |
133 | } | |
134 | ||
135 | return orig; | |
136 | } | |
137 | /*}}}*/ | |
138 | // RecordParser::ShortDesc - Return a 1 line description /*{{{*/ | |
139 | // --------------------------------------------------------------------- | |
140 | /* */ | |
141 | bool debRecordParser::ShortDesc(const char *&Start,const char *&End) | |
142 | { | |
143 | if (!LongDesc(Start,End)) | |
144 | return false; | |
145 | const char *Line = (const char *) memchr(Start, '\n', End - Start); | |
146 | if (Line != NULL) | |
147 | End = Line; | |
148 | return true; | |
149 | } | |
150 | /*}}}*/ | |
151 | // RecordParser::LongDesc - Return a longer description /*{{{*/ | |
152 | // --------------------------------------------------------------------- | |
153 | /* */ | |
154 | bool debRecordParser::LongDesc(const char *&Start,const char *&End) | |
155 | { | |
156 | if (!Section.Find("Description",Start,End)) | |
157 | return Section.Find(("Description-" + pkgIndexFile::LanguageCode()).c_str(),Start,End); | |
158 | return true; | |
159 | } | |
160 | /*}}}*/ | |
161 | ||
162 | static const char *SourceVerSeparators = " ()"; | |
163 | ||
164 | // RecordParser::SourcePkg - Return the source package name if any /*{{{*/ | |
165 | // --------------------------------------------------------------------- | |
166 | /* */ | |
167 | string debRecordParser::SourcePkg() | |
168 | { | |
169 | string Res = Section.FindS("Source"); | |
170 | string::size_type Pos = Res.find_first_of(SourceVerSeparators); | |
171 | if (Pos == string::npos) | |
172 | return Res; | |
173 | return string(Res,0,Pos); | |
174 | } | |
175 | /*}}}*/ | |
176 | // RecordParser::SourceVer - Return the source version number if present /*{{{*/ | |
177 | // --------------------------------------------------------------------- | |
178 | /* */ | |
179 | string debRecordParser::SourceVer() | |
180 | { | |
181 | string Pkg = Section.FindS("Source"); | |
182 | string::size_type Pos = Pkg.find_first_of(SourceVerSeparators); | |
183 | if (Pos == string::npos) | |
184 | return ""; | |
185 | ||
186 | string::size_type VerStart = Pkg.find_first_not_of(SourceVerSeparators, Pos); | |
187 | if(VerStart == string::npos) | |
188 | return ""; | |
189 | ||
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); | |
195 | else | |
196 | return string(Pkg, VerStart, VerEnd - VerStart); | |
197 | } | |
198 | /*}}}*/ | |
199 | // RecordParser::GetRec - Return the whole record /*{{{*/ | |
200 | // --------------------------------------------------------------------- | |
201 | /* */ | |
202 | void debRecordParser::GetRec(const char *&Start,const char *&Stop) | |
203 | { | |
204 | Section.GetSection(Start,Stop); | |
205 | } | |
206 | /*}}}*/ | |
207 | // RecordParser::Find - Locate a tag /*{{{*/ | |
208 | // --------------------------------------------------------------------- | |
209 | /* */ | |
210 | bool debRecordParser::Find(const char *Tag,const char *&Start, const char *&End) | |
211 | { | |
212 | return Section.Find(Tag,Start,End); | |
213 | } | |
214 | /*}}}*/ |