]>
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 /*{{{*/
12 #pragma implementation "apt-pkg/debrecords.h"
14 #include <apt-pkg/debrecords.h>
15 #include <apt-pkg/strutl.h>
16 #include <apt-pkg/error.h>
20 // RecordParser::debRecordParser - Constructor /*{{{*/
21 // ---------------------------------------------------------------------
23 debRecordParser::debRecordParser(string FileName
,pkgCache
&Cache
) :
24 File(FileName
,FileFd::ReadOnly
),
25 Tags(&File
,Cache
.Head().MaxVerFileSize
+ 200)
29 // RecordParser::Jump - Jump to a specific record /*{{{*/
30 // ---------------------------------------------------------------------
32 bool debRecordParser::Jump(pkgCache::VerFileIterator
const &Ver
)
34 return Tags
.Jump(Section
,Ver
->Offset
);
36 bool debRecordParser::Jump(pkgCache::DescFileIterator
const &Desc
)
38 return Tags
.Jump(Section
,Desc
->Offset
);
41 // RecordParser::FileName - Return the archive filename on the site /*{{{*/
42 // ---------------------------------------------------------------------
44 string
debRecordParser::FileName()
46 return Section
.FindS("Filename");
49 // RecordParser::Name - Return the package name /*{{{*/
50 // ---------------------------------------------------------------------
52 string
debRecordParser::Name()
54 return Section
.FindS("Package");
57 // RecordParser::MD5Hash - Return the archive hash /*{{{*/
58 // ---------------------------------------------------------------------
60 string
debRecordParser::MD5Hash()
62 return Section
.FindS("MD5Sum");
65 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
66 // ---------------------------------------------------------------------
68 string
debRecordParser::SHA1Hash()
70 return Section
.FindS("SHA1");
73 // RecordParser::Maintainer - Return the maintainer email /*{{{*/
74 // ---------------------------------------------------------------------
76 string
debRecordParser::Maintainer()
78 return Section
.FindS("Maintainer");
81 // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
82 // ---------------------------------------------------------------------
84 string
debRecordParser::ShortDesc()
86 string Res
= LongDesc();
87 string::size_type Pos
= Res
.find('\n');
88 if (Pos
== string::npos
)
90 return string(Res
,0,Pos
);
93 // RecordParser::LongDesc - Return a longer description /*{{{*/
94 // ---------------------------------------------------------------------
96 string
debRecordParser::LongDesc()
99 char *codeset
= nl_langinfo(CODESET
);
101 if (!Section
.FindS("Description").empty())
102 orig
= Section
.FindS("Description").c_str();
104 orig
= Section
.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str()).c_str();
106 if (strcmp(codeset
,"UTF-8") != 0) {
107 UTF8ToCodeset(codeset
, orig
, &dest
);
115 static const char *SourceVerSeparators
= " ()";
117 // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
118 // ---------------------------------------------------------------------
120 string
debRecordParser::SourcePkg()
122 string Res
= Section
.FindS("Source");
123 string::size_type Pos
= Res
.find_first_of(SourceVerSeparators
);
124 if (Pos
== string::npos
)
126 return string(Res
,0,Pos
);
129 // RecordParser::SourceVer - Return the source version number if present /*{{{*/
130 // ---------------------------------------------------------------------
132 string
debRecordParser::SourceVer()
134 string Pkg
= Section
.FindS("Source");
135 string::size_type Pos
= Pkg
.find_first_of(SourceVerSeparators
);
136 if (Pos
== string::npos
)
139 string::size_type VerStart
= Pkg
.find_first_not_of(SourceVerSeparators
, Pos
);
140 if(VerStart
== string::npos
)
143 string::size_type VerEnd
= Pkg
.find_first_of(SourceVerSeparators
, VerStart
);
144 if(VerEnd
== string::npos
)
145 // Corresponds to the case of, e.g., "foo (1.2" without a closing
146 // paren. Be liberal and guess what it means.
147 return string(Pkg
, VerStart
);
149 return string(Pkg
, VerStart
, VerEnd
- VerStart
);
152 // RecordParser::GetRec - Return the whole record /*{{{*/
153 // ---------------------------------------------------------------------
155 void debRecordParser::GetRec(const char *&Start
,const char *&Stop
)
157 Section
.GetSection(Start
,Stop
);