]>
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), | |
22 | Tags(&File,Cache.Head().MaxVerFileSize + 200) | |
f55ece0e AL |
23 | { |
24 | } | |
25 | /*}}}*/ | |
26 | // RecordParser::Jump - Jump to a specific record /*{{{*/ | |
27 | // --------------------------------------------------------------------- | |
28 | /* */ | |
03e39e59 | 29 | bool debRecordParser::Jump(pkgCache::VerFileIterator const &Ver) |
f55ece0e AL |
30 | { |
31 | return Tags.Jump(Section,Ver->Offset); | |
a52f938b OS |
32 | } |
33 | bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc) | |
34 | { | |
35 | return Tags.Jump(Section,Desc->Offset); | |
f55ece0e AL |
36 | } |
37 | /*}}}*/ | |
7e798dd7 AL |
38 | // RecordParser::FileName - Return the archive filename on the site /*{{{*/ |
39 | // --------------------------------------------------------------------- | |
40 | /* */ | |
41 | string debRecordParser::FileName() | |
42 | { | |
7974b907 | 43 | return Section.FindS("Filename"); |
7e798dd7 AL |
44 | } |
45 | /*}}}*/ | |
b2e465d6 AL |
46 | // RecordParser::Name - Return the package name /*{{{*/ |
47 | // --------------------------------------------------------------------- | |
48 | /* */ | |
49 | string debRecordParser::Name() | |
50 | { | |
51 | return Section.FindS("Package"); | |
52 | } | |
53 | /*}}}*/ | |
7e798dd7 AL |
54 | // RecordParser::MD5Hash - Return the archive hash /*{{{*/ |
55 | // --------------------------------------------------------------------- | |
56 | /* */ | |
57 | string debRecordParser::MD5Hash() | |
58 | { | |
a7c835af AL |
59 | return Section.FindS("MD5Sum"); |
60 | } | |
61 | /*}}}*/ | |
62 | // RecordParser::SHA1Hash - Return the archive hash /*{{{*/ | |
63 | // --------------------------------------------------------------------- | |
64 | /* */ | |
65 | string debRecordParser::SHA1Hash() | |
66 | { | |
59b46c41 | 67 | return Section.FindS("SHA1"); |
7e798dd7 AL |
68 | } |
69 | /*}}}*/ | |
70 | // RecordParser::Maintainer - Return the maintainer email /*{{{*/ | |
71 | // --------------------------------------------------------------------- | |
72 | /* */ | |
73 | string debRecordParser::Maintainer() | |
74 | { | |
7974b907 | 75 | return Section.FindS("Maintainer"); |
7e798dd7 AL |
76 | } |
77 | /*}}}*/ | |
78 | // RecordParser::ShortDesc - Return a 1 line description /*{{{*/ | |
79 | // --------------------------------------------------------------------- | |
80 | /* */ | |
81 | string debRecordParser::ShortDesc() | |
82 | { | |
a52f938b | 83 | string Res = LongDesc(); |
7e798dd7 AL |
84 | string::size_type Pos = Res.find('\n'); |
85 | if (Pos == string::npos) | |
86 | return Res; | |
87 | return string(Res,0,Pos); | |
88 | } | |
89 | /*}}}*/ | |
90 | // RecordParser::LongDesc - Return a longer description /*{{{*/ | |
91 | // --------------------------------------------------------------------- | |
92 | /* */ | |
93 | string debRecordParser::LongDesc() | |
94 | { | |
a52f938b OS |
95 | string orig, dest; |
96 | char *codeset = nl_langinfo(CODESET); | |
97 | ||
98 | if (!Section.FindS("Description").empty()) | |
99 | orig = Section.FindS("Description").c_str(); | |
100 | else | |
101 | orig = Section.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str()).c_str(); | |
102 | ||
103 | if (strcmp(codeset,"UTF-8") != 0) { | |
104 | UTF8ToCodeset(codeset, orig, &dest); | |
105 | orig = dest; | |
106 | } | |
107 | ||
108 | return orig; | |
7e798dd7 AL |
109 | } |
110 | /*}}}*/ | |
c2f2b862 MV |
111 | |
112 | static const char *SourceVerSeparators = " ()"; | |
113 | ||
04f232fc | 114 | // RecordParser::SourcePkg - Return the source package name if any /*{{{*/ |
36375005 AL |
115 | // --------------------------------------------------------------------- |
116 | /* */ | |
117 | string debRecordParser::SourcePkg() | |
118 | { | |
04f232fc | 119 | string Res = Section.FindS("Source"); |
c2f2b862 | 120 | string::size_type Pos = Res.find_first_of(SourceVerSeparators); |
04f232fc AL |
121 | if (Pos == string::npos) |
122 | return Res; | |
123 | return string(Res,0,Pos); | |
36375005 AL |
124 | } |
125 | /*}}}*/ | |
c2f2b862 MV |
126 | // RecordParser::SourceVer - Return the source version number if present /*{{{*/ |
127 | // --------------------------------------------------------------------- | |
128 | /* */ | |
129 | string debRecordParser::SourceVer() | |
130 | { | |
131 | string Pkg = Section.FindS("Source"); | |
132 | string::size_type Pos = Pkg.find_first_of(SourceVerSeparators); | |
133 | if (Pos == string::npos) | |
134 | return ""; | |
135 | ||
136 | string::size_type VerStart = Pkg.find_first_not_of(SourceVerSeparators, Pos); | |
137 | if(VerStart == string::npos) | |
138 | return ""; | |
139 | ||
140 | string::size_type VerEnd = Pkg.find_first_of(SourceVerSeparators, VerStart); | |
141 | if(VerEnd == string::npos) | |
142 | // Corresponds to the case of, e.g., "foo (1.2" without a closing | |
143 | // paren. Be liberal and guess what it means. | |
144 | return string(Pkg, VerStart); | |
145 | else | |
146 | return string(Pkg, VerStart, VerEnd - VerStart); | |
147 | } | |
148 | /*}}}*/ | |
b2e465d6 AL |
149 | // RecordParser::GetRec - Return the whole record /*{{{*/ |
150 | // --------------------------------------------------------------------- | |
151 | /* */ | |
152 | void debRecordParser::GetRec(const char *&Start,const char *&Stop) | |
153 | { | |
154 | Section.GetSection(Start,Stop); | |
155 | } | |
156 | /*}}}*/ |