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