]>
git.saurik.com Git - apt.git/blob - apt-pkg/deb/debrecords.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: debrecords.cc,v 1.10 2001/03/13 06:51:46 jgg Exp $
4 /* ######################################################################
6 Debian Package Records - Parser for debian package records
8 ##################################################################### */
10 // Include Files /*{{{*/
11 #include <apt-pkg/debrecords.h>
12 #include <apt-pkg/strutl.h>
13 #include <apt-pkg/error.h>
14 #include <apt-pkg/aptconfiguration.h>
18 // RecordParser::debRecordParser - Constructor /*{{{*/
19 // ---------------------------------------------------------------------
21 debRecordParser::debRecordParser(string FileName
,pkgCache
&Cache
) :
22 File(FileName
,FileFd::ReadOnly
),
23 Tags(&File
,Cache
.Head().MaxVerFileSize
+ 200)
27 // RecordParser::Jump - Jump to a specific record /*{{{*/
28 // ---------------------------------------------------------------------
30 bool debRecordParser::Jump(pkgCache::VerFileIterator
const &Ver
)
32 return Tags
.Jump(Section
,Ver
->Offset
);
34 bool debRecordParser::Jump(pkgCache::DescFileIterator
const &Desc
)
36 return Tags
.Jump(Section
,Desc
->Offset
);
39 // RecordParser::FileName - Return the archive filename on the site /*{{{*/
40 // ---------------------------------------------------------------------
42 string
debRecordParser::FileName()
44 return Section
.FindS("Filename");
47 // RecordParser::Name - Return the package name /*{{{*/
48 // ---------------------------------------------------------------------
50 string
debRecordParser::Name()
52 return Section
.FindS("Package");
55 // RecordParser::Homepage - Return the package homepage /*{{{*/
56 // ---------------------------------------------------------------------
58 string
debRecordParser::Homepage()
60 return Section
.FindS("Homepage");
63 // RecordParser::MD5Hash - Return the archive hash /*{{{*/
64 // ---------------------------------------------------------------------
66 string
debRecordParser::MD5Hash()
68 return Section
.FindS("MD5Sum");
71 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
72 // ---------------------------------------------------------------------
74 string
debRecordParser::SHA1Hash()
76 return Section
.FindS("SHA1");
79 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
80 // ---------------------------------------------------------------------
82 string
debRecordParser::SHA256Hash()
84 return Section
.FindS("SHA256");
87 // RecordParser::Maintainer - Return the maintainer email /*{{{*/
88 // ---------------------------------------------------------------------
90 string
debRecordParser::Maintainer()
92 return Section
.FindS("Maintainer");
95 // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
96 // ---------------------------------------------------------------------
98 string
debRecordParser::ShortDesc()
100 string Res
= LongDesc();
101 string::size_type Pos
= Res
.find('\n');
102 if (Pos
== string::npos
)
104 return string(Res
,0,Pos
);
107 // RecordParser::LongDesc - Return a longer description /*{{{*/
108 // ---------------------------------------------------------------------
110 string
debRecordParser::LongDesc()
114 if (!Section
.FindS("Description").empty())
115 orig
= Section
.FindS("Description").c_str();
118 vector
<string
> const lang
= APT::Configuration::getLanguages();
119 for (vector
<string
>::const_iterator l
= lang
.begin();
120 orig
.empty() && l
!= lang
.end(); l
++)
121 orig
= Section
.FindS(string("Description-").append(*l
).c_str());
124 char const * const codeset
= nl_langinfo(CODESET
);
125 if (strcmp(codeset
,"UTF-8") != 0) {
126 UTF8ToCodeset(codeset
, orig
, &dest
);
134 static const char *SourceVerSeparators
= " ()";
136 // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
137 // ---------------------------------------------------------------------
139 string
debRecordParser::SourcePkg()
141 string Res
= Section
.FindS("Source");
142 string::size_type Pos
= Res
.find_first_of(SourceVerSeparators
);
143 if (Pos
== string::npos
)
145 return string(Res
,0,Pos
);
148 // RecordParser::SourceVer - Return the source version number if present /*{{{*/
149 // ---------------------------------------------------------------------
151 string
debRecordParser::SourceVer()
153 string Pkg
= Section
.FindS("Source");
154 string::size_type Pos
= Pkg
.find_first_of(SourceVerSeparators
);
155 if (Pos
== string::npos
)
158 string::size_type VerStart
= Pkg
.find_first_not_of(SourceVerSeparators
, Pos
);
159 if(VerStart
== string::npos
)
162 string::size_type VerEnd
= Pkg
.find_first_of(SourceVerSeparators
, VerStart
);
163 if(VerEnd
== string::npos
)
164 // Corresponds to the case of, e.g., "foo (1.2" without a closing
165 // paren. Be liberal and guess what it means.
166 return string(Pkg
, VerStart
);
168 return string(Pkg
, VerStart
, VerEnd
- VerStart
);
171 // RecordParser::GetRec - Return the whole record /*{{{*/
172 // ---------------------------------------------------------------------
174 void debRecordParser::GetRec(const char *&Start
,const char *&Stop
)
176 Section
.GetSection(Start
,Stop
);