]>
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::ReadOnlyGzip
),
23 Tags(&File
, std::max(Cache
.Head().MaxVerFileSize
,
24 Cache
.Head().MaxDescFileSize
) + 200)
28 // RecordParser::Jump - Jump to a specific record /*{{{*/
29 // ---------------------------------------------------------------------
31 bool debRecordParser::Jump(pkgCache::VerFileIterator
const &Ver
)
33 return Tags
.Jump(Section
,Ver
->Offset
);
35 bool debRecordParser::Jump(pkgCache::DescFileIterator
const &Desc
)
37 return Tags
.Jump(Section
,Desc
->Offset
);
40 // RecordParser::FileName - Return the archive filename on the site /*{{{*/
41 // ---------------------------------------------------------------------
43 string
debRecordParser::FileName()
45 return Section
.FindS("Filename");
48 // RecordParser::Name - Return the package name /*{{{*/
49 // ---------------------------------------------------------------------
51 string
debRecordParser::Name()
53 return Section
.FindS("Package");
56 // RecordParser::Homepage - Return the package homepage /*{{{*/
57 // ---------------------------------------------------------------------
59 string
debRecordParser::Homepage()
61 return Section
.FindS("Homepage");
64 // RecordParser::MD5Hash - Return the archive hash /*{{{*/
65 // ---------------------------------------------------------------------
67 string
debRecordParser::MD5Hash()
69 return Section
.FindS("MD5Sum");
72 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
73 // ---------------------------------------------------------------------
75 string
debRecordParser::SHA1Hash()
77 return Section
.FindS("SHA1");
80 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
81 // ---------------------------------------------------------------------
83 string
debRecordParser::SHA256Hash()
85 return Section
.FindS("SHA256");
88 // RecordParser::Maintainer - Return the maintainer email /*{{{*/
89 // ---------------------------------------------------------------------
91 string
debRecordParser::Maintainer()
93 return Section
.FindS("Maintainer");
96 // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
97 // ---------------------------------------------------------------------
99 string
debRecordParser::ShortDesc()
101 string Res
= LongDesc();
102 string::size_type Pos
= Res
.find('\n');
103 if (Pos
== string::npos
)
105 return string(Res
,0,Pos
);
108 // RecordParser::LongDesc - Return a longer description /*{{{*/
109 // ---------------------------------------------------------------------
111 string
debRecordParser::LongDesc()
115 if (!Section
.FindS("Description").empty())
116 orig
= Section
.FindS("Description").c_str();
119 vector
<string
> const lang
= APT::Configuration::getLanguages();
120 for (vector
<string
>::const_iterator l
= lang
.begin();
121 orig
.empty() && l
!= lang
.end(); l
++)
122 orig
= Section
.FindS(string("Description-").append(*l
).c_str());
125 char const * const codeset
= nl_langinfo(CODESET
);
126 if (strcmp(codeset
,"UTF-8") != 0) {
127 UTF8ToCodeset(codeset
, orig
, &dest
);
135 static const char *SourceVerSeparators
= " ()";
137 // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
138 // ---------------------------------------------------------------------
140 string
debRecordParser::SourcePkg()
142 string Res
= Section
.FindS("Source");
143 string::size_type Pos
= Res
.find_first_of(SourceVerSeparators
);
144 if (Pos
== string::npos
)
146 return string(Res
,0,Pos
);
149 // RecordParser::SourceVer - Return the source version number if present /*{{{*/
150 // ---------------------------------------------------------------------
152 string
debRecordParser::SourceVer()
154 string Pkg
= Section
.FindS("Source");
155 string::size_type Pos
= Pkg
.find_first_of(SourceVerSeparators
);
156 if (Pos
== string::npos
)
159 string::size_type VerStart
= Pkg
.find_first_not_of(SourceVerSeparators
, Pos
);
160 if(VerStart
== string::npos
)
163 string::size_type VerEnd
= Pkg
.find_first_of(SourceVerSeparators
, VerStart
);
164 if(VerEnd
== string::npos
)
165 // Corresponds to the case of, e.g., "foo (1.2" without a closing
166 // paren. Be liberal and guess what it means.
167 return string(Pkg
, VerStart
);
169 return string(Pkg
, VerStart
, VerEnd
- VerStart
);
172 // RecordParser::GetRec - Return the whole record /*{{{*/
173 // ---------------------------------------------------------------------
175 void debRecordParser::GetRec(const char *&Start
,const char *&Stop
)
177 Section
.GetSection(Start
,Stop
);