]>
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>
17 // RecordParser::debRecordParser - Constructor /*{{{*/
18 // ---------------------------------------------------------------------
20 debRecordParser::debRecordParser(string FileName
,pkgCache
&Cache
) :
21 File(FileName
,FileFd::ReadOnly
),
22 Tags(&File
,Cache
.Head().MaxVerFileSize
+ 200)
26 // RecordParser::Jump - Jump to a specific record /*{{{*/
27 // ---------------------------------------------------------------------
29 bool debRecordParser::Jump(pkgCache::VerFileIterator
const &Ver
)
31 return Tags
.Jump(Section
,Ver
->Offset
);
33 bool debRecordParser::Jump(pkgCache::DescFileIterator
const &Desc
)
35 return Tags
.Jump(Section
,Desc
->Offset
);
38 // RecordParser::FileName - Return the archive filename on the site /*{{{*/
39 // ---------------------------------------------------------------------
41 string
debRecordParser::FileName()
43 return Section
.FindS("Filename");
46 // RecordParser::Name - Return the package name /*{{{*/
47 // ---------------------------------------------------------------------
49 string
debRecordParser::Name()
51 return Section
.FindS("Package");
54 // RecordParser::Homepage - Return the package homepage /*{{{*/
55 // ---------------------------------------------------------------------
57 string
debRecordParser::Homepage()
59 return Section
.FindS("Homepage");
62 // RecordParser::MD5Hash - Return the archive hash /*{{{*/
63 // ---------------------------------------------------------------------
65 string
debRecordParser::MD5Hash()
67 return Section
.FindS("MD5Sum");
70 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
71 // ---------------------------------------------------------------------
73 string
debRecordParser::SHA1Hash()
75 return Section
.FindS("SHA1");
78 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
79 // ---------------------------------------------------------------------
81 string
debRecordParser::SHA256Hash()
83 return Section
.FindS("SHA256");
86 // RecordParser::Maintainer - Return the maintainer email /*{{{*/
87 // ---------------------------------------------------------------------
89 string
debRecordParser::Maintainer()
91 return Section
.FindS("Maintainer");
94 // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
95 // ---------------------------------------------------------------------
97 string
debRecordParser::ShortDesc()
99 string Res
= LongDesc();
100 string::size_type Pos
= Res
.find('\n');
101 if (Pos
== string::npos
)
103 return string(Res
,0,Pos
);
106 // RecordParser::LongDesc - Return a longer description /*{{{*/
107 // ---------------------------------------------------------------------
109 string
debRecordParser::LongDesc()
112 char *codeset
= nl_langinfo(CODESET
);
114 if (!Section
.FindS("Description").empty())
115 orig
= Section
.FindS("Description").c_str();
117 orig
= Section
.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str()).c_str();
119 if (strcmp(codeset
,"UTF-8") != 0) {
120 UTF8ToCodeset(codeset
, orig
, &dest
);
128 static const char *SourceVerSeparators
= " ()";
130 // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
131 // ---------------------------------------------------------------------
133 string
debRecordParser::SourcePkg()
135 string Res
= Section
.FindS("Source");
136 string::size_type Pos
= Res
.find_first_of(SourceVerSeparators
);
137 if (Pos
== string::npos
)
139 return string(Res
,0,Pos
);
142 // RecordParser::SourceVer - Return the source version number if present /*{{{*/
143 // ---------------------------------------------------------------------
145 string
debRecordParser::SourceVer()
147 string Pkg
= Section
.FindS("Source");
148 string::size_type Pos
= Pkg
.find_first_of(SourceVerSeparators
);
149 if (Pos
== string::npos
)
152 string::size_type VerStart
= Pkg
.find_first_not_of(SourceVerSeparators
, Pos
);
153 if(VerStart
== string::npos
)
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
);
162 return string(Pkg
, VerStart
, VerEnd
- VerStart
);
165 // RecordParser::GetRec - Return the whole record /*{{{*/
166 // ---------------------------------------------------------------------
168 void debRecordParser::GetRec(const char *&Start
,const char *&Stop
)
170 Section
.GetSection(Start
,Stop
);