]>
Commit | Line | Data |
---|---|---|
f55ece0e AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
a7c835af | 3 | // $Id: debrecords.cc,v 1.10 2001/03/13 06:51:46 jgg Exp $ |
f55ece0e AL |
4 | /* ###################################################################### |
5 | ||
6 | Debian Package Records - Parser for debian package records | |
7 | ||
8 | ##################################################################### */ | |
9 | /*}}}*/ | |
10 | // Include Files /*{{{*/ | |
f55ece0e | 11 | #include <apt-pkg/debrecords.h> |
a52f938b | 12 | #include <apt-pkg/strutl.h> |
f55ece0e | 13 | #include <apt-pkg/error.h> |
a52f938b | 14 | #include <langinfo.h> |
f55ece0e AL |
15 | /*}}}*/ |
16 | ||
17 | // RecordParser::debRecordParser - Constructor /*{{{*/ | |
18 | // --------------------------------------------------------------------- | |
19 | /* */ | |
b2e465d6 AL |
20 | debRecordParser::debRecordParser(string FileName,pkgCache &Cache) : |
21 | File(FileName,FileFd::ReadOnly), | |
eea96cc7 MV |
22 | Tags(&File, std::max(Cache.Head().MaxVerFileSize, |
23 | Cache.Head().MaxDescFileSize) + 200) | |
f55ece0e AL |
24 | { |
25 | } | |
26 | /*}}}*/ | |
27 | // RecordParser::Jump - Jump to a specific record /*{{{*/ | |
28 | // --------------------------------------------------------------------- | |
29 | /* */ | |
03e39e59 | 30 | bool debRecordParser::Jump(pkgCache::VerFileIterator const &Ver) |
f55ece0e AL |
31 | { |
32 | return Tags.Jump(Section,Ver->Offset); | |
a52f938b OS |
33 | } |
34 | bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc) | |
35 | { | |
36 | return Tags.Jump(Section,Desc->Offset); | |
f55ece0e AL |
37 | } |
38 | /*}}}*/ | |
7e798dd7 AL |
39 | // RecordParser::FileName - Return the archive filename on the site /*{{{*/ |
40 | // --------------------------------------------------------------------- | |
41 | /* */ | |
42 | string debRecordParser::FileName() | |
43 | { | |
7974b907 | 44 | return Section.FindS("Filename"); |
7e798dd7 AL |
45 | } |
46 | /*}}}*/ | |
b2e465d6 AL |
47 | // RecordParser::Name - Return the package name /*{{{*/ |
48 | // --------------------------------------------------------------------- | |
49 | /* */ | |
50 | string debRecordParser::Name() | |
51 | { | |
52 | return Section.FindS("Package"); | |
53 | } | |
54 | /*}}}*/ | |
f27b4a70 OS |
55 | // RecordParser::Homepage - Return the package homepage /*{{{*/ |
56 | // --------------------------------------------------------------------- | |
57 | /* */ | |
58 | string debRecordParser::Homepage() | |
59 | { | |
60 | return Section.FindS("Homepage"); | |
61 | } | |
62 | /*}}}*/ | |
7e798dd7 AL |
63 | // RecordParser::MD5Hash - Return the archive hash /*{{{*/ |
64 | // --------------------------------------------------------------------- | |
65 | /* */ | |
66 | string debRecordParser::MD5Hash() | |
67 | { | |
a7c835af AL |
68 | return Section.FindS("MD5Sum"); |
69 | } | |
70 | /*}}}*/ | |
71 | // RecordParser::SHA1Hash - Return the archive hash /*{{{*/ | |
72 | // --------------------------------------------------------------------- | |
73 | /* */ | |
74 | string debRecordParser::SHA1Hash() | |
75 | { | |
59b46c41 | 76 | return Section.FindS("SHA1"); |
7e798dd7 AL |
77 | } |
78 | /*}}}*/ | |
495e5cb2 MV |
79 | // RecordParser::SHA1Hash - Return the archive hash /*{{{*/ |
80 | // --------------------------------------------------------------------- | |
81 | /* */ | |
82 | string debRecordParser::SHA256Hash() | |
83 | { | |
84 | return Section.FindS("SHA256"); | |
85 | } | |
86 | /*}}}*/ | |
7e798dd7 AL |
87 | // RecordParser::Maintainer - Return the maintainer email /*{{{*/ |
88 | // --------------------------------------------------------------------- | |
89 | /* */ | |
90 | string debRecordParser::Maintainer() | |
91 | { | |
7974b907 | 92 | return Section.FindS("Maintainer"); |
7e798dd7 AL |
93 | } |
94 | /*}}}*/ | |
95 | // RecordParser::ShortDesc - Return a 1 line description /*{{{*/ | |
96 | // --------------------------------------------------------------------- | |
97 | /* */ | |
98 | string debRecordParser::ShortDesc() | |
99 | { | |
a52f938b | 100 | string Res = LongDesc(); |
7e798dd7 AL |
101 | string::size_type Pos = Res.find('\n'); |
102 | if (Pos == string::npos) | |
103 | return Res; | |
104 | return string(Res,0,Pos); | |
105 | } | |
106 | /*}}}*/ | |
107 | // RecordParser::LongDesc - Return a longer description /*{{{*/ | |
108 | // --------------------------------------------------------------------- | |
109 | /* */ | |
110 | string debRecordParser::LongDesc() | |
111 | { | |
a52f938b OS |
112 | string orig, dest; |
113 | char *codeset = nl_langinfo(CODESET); | |
114 | ||
115 | if (!Section.FindS("Description").empty()) | |
116 | orig = Section.FindS("Description").c_str(); | |
117 | else | |
118 | orig = Section.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str()).c_str(); | |
119 | ||
120 | if (strcmp(codeset,"UTF-8") != 0) { | |
121 | UTF8ToCodeset(codeset, orig, &dest); | |
122 | orig = dest; | |
123 | } | |
124 | ||
125 | return orig; | |
7e798dd7 AL |
126 | } |
127 | /*}}}*/ | |
c2f2b862 MV |
128 | |
129 | static const char *SourceVerSeparators = " ()"; | |
130 | ||
04f232fc | 131 | // RecordParser::SourcePkg - Return the source package name if any /*{{{*/ |
36375005 AL |
132 | // --------------------------------------------------------------------- |
133 | /* */ | |
134 | string debRecordParser::SourcePkg() | |
135 | { | |
04f232fc | 136 | string Res = Section.FindS("Source"); |
c2f2b862 | 137 | string::size_type Pos = Res.find_first_of(SourceVerSeparators); |
04f232fc AL |
138 | if (Pos == string::npos) |
139 | return Res; | |
140 | return string(Res,0,Pos); | |
36375005 AL |
141 | } |
142 | /*}}}*/ | |
c2f2b862 MV |
143 | // RecordParser::SourceVer - Return the source version number if present /*{{{*/ |
144 | // --------------------------------------------------------------------- | |
145 | /* */ | |
146 | string debRecordParser::SourceVer() | |
147 | { | |
148 | string Pkg = Section.FindS("Source"); | |
149 | string::size_type Pos = Pkg.find_first_of(SourceVerSeparators); | |
150 | if (Pos == string::npos) | |
151 | return ""; | |
152 | ||
153 | string::size_type VerStart = Pkg.find_first_not_of(SourceVerSeparators, Pos); | |
154 | if(VerStart == string::npos) | |
155 | return ""; | |
156 | ||
157 | string::size_type VerEnd = Pkg.find_first_of(SourceVerSeparators, VerStart); | |
158 | if(VerEnd == string::npos) | |
159 | // Corresponds to the case of, e.g., "foo (1.2" without a closing | |
160 | // paren. Be liberal and guess what it means. | |
161 | return string(Pkg, VerStart); | |
162 | else | |
163 | return string(Pkg, VerStart, VerEnd - VerStart); | |
164 | } | |
165 | /*}}}*/ | |
b2e465d6 AL |
166 | // RecordParser::GetRec - Return the whole record /*{{{*/ |
167 | // --------------------------------------------------------------------- | |
168 | /* */ | |
169 | void debRecordParser::GetRec(const char *&Start,const char *&Stop) | |
170 | { | |
171 | Section.GetSection(Start,Stop); | |
172 | } | |
173 | /*}}}*/ |