]> git.saurik.com Git - apt.git/blob - apt-pkg/deb/debrecords.cc
* merged dpkg-log branch
[apt.git] / apt-pkg / deb / debrecords.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: debrecords.cc,v 1.10 2001/03/13 06:51:46 jgg Exp $
4 /* ######################################################################
5
6 Debian Package Records - Parser for debian package records
7
8 ##################################################################### */
9 /*}}}*/
10 // Include Files /*{{{*/
11 #include <apt-pkg/debrecords.h>
12 #include <apt-pkg/strutl.h>
13 #include <apt-pkg/error.h>
14 #include <langinfo.h>
15 /*}}}*/
16
17 // RecordParser::debRecordParser - Constructor /*{{{*/
18 // ---------------------------------------------------------------------
19 /* */
20 debRecordParser::debRecordParser(string FileName,pkgCache &Cache) :
21 File(FileName,FileFd::ReadOnly),
22 Tags(&File,Cache.Head().MaxVerFileSize + 200)
23 {
24 }
25 /*}}}*/
26 // RecordParser::Jump - Jump to a specific record /*{{{*/
27 // ---------------------------------------------------------------------
28 /* */
29 bool debRecordParser::Jump(pkgCache::VerFileIterator const &Ver)
30 {
31 return Tags.Jump(Section,Ver->Offset);
32 }
33 bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc)
34 {
35 return Tags.Jump(Section,Desc->Offset);
36 }
37 /*}}}*/
38 // RecordParser::FileName - Return the archive filename on the site /*{{{*/
39 // ---------------------------------------------------------------------
40 /* */
41 string debRecordParser::FileName()
42 {
43 return Section.FindS("Filename");
44 }
45 /*}}}*/
46 // RecordParser::Name - Return the package name /*{{{*/
47 // ---------------------------------------------------------------------
48 /* */
49 string debRecordParser::Name()
50 {
51 return Section.FindS("Package");
52 }
53 /*}}}*/
54 // RecordParser::MD5Hash - Return the archive hash /*{{{*/
55 // ---------------------------------------------------------------------
56 /* */
57 string debRecordParser::MD5Hash()
58 {
59 return Section.FindS("MD5Sum");
60 }
61 /*}}}*/
62 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
63 // ---------------------------------------------------------------------
64 /* */
65 string debRecordParser::SHA1Hash()
66 {
67 return Section.FindS("SHA1");
68 }
69 /*}}}*/
70 // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
71 // ---------------------------------------------------------------------
72 /* */
73 string debRecordParser::SHA256Hash()
74 {
75 return Section.FindS("SHA256");
76 }
77 /*}}}*/
78 // RecordParser::Maintainer - Return the maintainer email /*{{{*/
79 // ---------------------------------------------------------------------
80 /* */
81 string debRecordParser::Maintainer()
82 {
83 return Section.FindS("Maintainer");
84 }
85 /*}}}*/
86 // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
87 // ---------------------------------------------------------------------
88 /* */
89 string debRecordParser::ShortDesc()
90 {
91 string Res = LongDesc();
92 string::size_type Pos = Res.find('\n');
93 if (Pos == string::npos)
94 return Res;
95 return string(Res,0,Pos);
96 }
97 /*}}}*/
98 // RecordParser::LongDesc - Return a longer description /*{{{*/
99 // ---------------------------------------------------------------------
100 /* */
101 string debRecordParser::LongDesc()
102 {
103 string orig, dest;
104 char *codeset = nl_langinfo(CODESET);
105
106 if (!Section.FindS("Description").empty())
107 orig = Section.FindS("Description").c_str();
108 else
109 orig = Section.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str()).c_str();
110
111 if (strcmp(codeset,"UTF-8") != 0) {
112 UTF8ToCodeset(codeset, orig, &dest);
113 orig = dest;
114 }
115
116 return orig;
117 }
118 /*}}}*/
119
120 static const char *SourceVerSeparators = " ()";
121
122 // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
123 // ---------------------------------------------------------------------
124 /* */
125 string debRecordParser::SourcePkg()
126 {
127 string Res = Section.FindS("Source");
128 string::size_type Pos = Res.find_first_of(SourceVerSeparators);
129 if (Pos == string::npos)
130 return Res;
131 return string(Res,0,Pos);
132 }
133 /*}}}*/
134 // RecordParser::SourceVer - Return the source version number if present /*{{{*/
135 // ---------------------------------------------------------------------
136 /* */
137 string debRecordParser::SourceVer()
138 {
139 string Pkg = Section.FindS("Source");
140 string::size_type Pos = Pkg.find_first_of(SourceVerSeparators);
141 if (Pos == string::npos)
142 return "";
143
144 string::size_type VerStart = Pkg.find_first_not_of(SourceVerSeparators, Pos);
145 if(VerStart == string::npos)
146 return "";
147
148 string::size_type VerEnd = Pkg.find_first_of(SourceVerSeparators, VerStart);
149 if(VerEnd == string::npos)
150 // Corresponds to the case of, e.g., "foo (1.2" without a closing
151 // paren. Be liberal and guess what it means.
152 return string(Pkg, VerStart);
153 else
154 return string(Pkg, VerStart, VerEnd - VerStart);
155 }
156 /*}}}*/
157 // RecordParser::GetRec - Return the whole record /*{{{*/
158 // ---------------------------------------------------------------------
159 /* */
160 void debRecordParser::GetRec(const char *&Start,const char *&Stop)
161 {
162 Section.GetSection(Start,Stop);
163 }
164 /*}}}*/