]> git.saurik.com Git - apt.git/blame - apt-pkg/deb/debsrcrecords.cc
* apt-pkg/deb/dpkgpm.cc:
[apt.git] / apt-pkg / deb / debsrcrecords.cc
CommitLineData
11e7af84
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
c33b707e 3// $Id: debsrcrecords.cc,v 1.6 2004/03/17 05:58:54 mdz Exp $
11e7af84
AL
4/* ######################################################################
5
6 Debian Source Package Records - Parser implementation for Debian style
7 source indexes
8
9 ##################################################################### */
10 /*}}}*/
11// Include Files /*{{{*/
b2e465d6 12#include <apt-pkg/deblistparser.h>
11e7af84
AL
13#include <apt-pkg/debsrcrecords.h>
14#include <apt-pkg/error.h>
36f610f1 15#include <apt-pkg/strutl.h>
b2e465d6 16#include <apt-pkg/configuration.h>
4ab24e53
MV
17
18using std::max;
11e7af84
AL
19 /*}}}*/
20
21// SrcRecordParser::Binaries - Return the binaries field /*{{{*/
22// ---------------------------------------------------------------------
23/* This member parses the binaries field into a pair of class arrays and
24 returns a list of strings representing all of the components of the
25 binaries field. The returned array need not be freed and will be
b2e465d6
AL
26 reused by the next Binaries function call. This function is commonly
27 used during scanning to find the right package */
11e7af84
AL
28const char **debSrcRecordParser::Binaries()
29{
b2e465d6 30 // This should use Start/Stop too, it is supposed to be efficient after all.
11e7af84 31 string Bins = Sect.FindS("Binary");
c33b707e 32 if (Bins.empty() == true || Bins.length() >= 102400)
11e7af84
AL
33 return 0;
34
d295f24c 35 if (Bins.length() >= BufSize)
c33b707e 36 {
4ab24e53
MV
37 delete [] Buffer;
38 // allocate new size based on buffer (but never smaller than 4000)
19ec5723 39 BufSize = max((unsigned int)4000, max((unsigned int)Bins.length()+1,2*BufSize));
4ab24e53 40 Buffer = new char[BufSize];
c33b707e
AL
41 }
42
4ab24e53
MV
43 strcpy(Buffer,Bins.c_str());
44 if (TokSplitString(',',Buffer,StaticBinList,
b2e465d6
AL
45 sizeof(StaticBinList)/sizeof(StaticBinList[0])) == false)
46 return 0;
c33b707e 47
b2e465d6
AL
48 return (const char **)StaticBinList;
49}
50 /*}}}*/
51// SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/
52// ---------------------------------------------------------------------
53/* This member parses the build-depends information and returns a list of
54 package/version records representing the build dependency. The returned
55 array need not be freed and will be reused by the next call to this
56 function */
41c81fd8
DK
57bool debSrcRecordParser::BuildDepends(vector<pkgSrcRecords::Parser::BuildDepRec> &BuildDeps,
58 bool const &ArchOnly, bool const &StripMultiArch)
b2e465d6
AL
59{
60 unsigned int I;
61 const char *Start, *Stop;
62 BuildDepRec rec;
63 const char *fields[] = {"Build-Depends",
64 "Build-Depends-Indep",
65 "Build-Conflicts",
66 "Build-Conflicts-Indep"};
67
68 BuildDeps.clear();
11e7af84 69
b2e465d6 70 for (I = 0; I < 4; I++)
11e7af84 71 {
45430cbf
AL
72 if (ArchOnly && (I == 1 || I == 3))
73 continue;
74
b2e465d6
AL
75 if (Sect.Find(fields[I], Start, Stop) == false)
76 continue;
11e7af84 77
b2e465d6
AL
78 while (1)
79 {
80 Start = debListParser::ParseDepends(Start, Stop,
41c81fd8 81 rec.Package,rec.Version,rec.Op,true, StripMultiArch);
b2e465d6
AL
82
83 if (Start == 0)
84 return _error->Error("Problem parsing dependency: %s", fields[I]);
85 rec.Type = I;
86
87 if (rec.Package != "")
88 BuildDeps.push_back(rec);
89
90 if (Start == Stop)
91 break;
92 }
11e7af84
AL
93 }
94
b2e465d6 95 return true;
11e7af84
AL
96}
97 /*}}}*/
36f610f1
AL
98// SrcRecordParser::Files - Return a list of files for this source /*{{{*/
99// ---------------------------------------------------------------------
100/* This parses the list of files and returns it, each file is required to have
101 a complete source package */
102bool debSrcRecordParser::Files(vector<pkgSrcRecords::File> &List)
103{
104 List.erase(List.begin(),List.end());
105
106 string Files = Sect.FindS("Files");
107 if (Files.empty() == true)
108 return false;
109
110 // Stash the / terminated directory prefix
36375005 111 string Base = Sect.FindS("Directory");
36f610f1
AL
112 if (Base.empty() == false && Base[Base.length()-1] != '/')
113 Base += '/';
36375005 114
36f610f1
AL
115 // Iterate over the entire list grabbing each triplet
116 const char *C = Files.c_str();
117 while (*C != 0)
118 {
119 pkgSrcRecords::File F;
120 string Size;
121
122 // Parse each of the elements
123 if (ParseQuoteWord(C,F.MD5Hash) == false ||
124 ParseQuoteWord(C,Size) == false ||
125 ParseQuoteWord(C,F.Path) == false)
126 return _error->Error("Error parsing file record");
127
128 // Parse the size and append the directory
129 F.Size = atoi(Size.c_str());
130 F.Path = Base + F.Path;
b2e465d6
AL
131
132 // Try to guess what sort of file it is we are getting.
133 string::size_type Pos = F.Path.length()-1;
134 while (1)
135 {
136 string::size_type Tmp = F.Path.rfind('.',Pos);
137 if (Tmp == string::npos)
138 break;
164994f5
DK
139 if (F.Type == "tar") {
140 // source v3 has extension 'debian.tar.*' instead of 'diff.*'
141 if (string(F.Path, Tmp+1, Pos-Tmp) == "debian")
142 F.Type = "diff";
143 break;
144 }
b2e465d6
AL
145 F.Type = string(F.Path,Tmp+1,Pos-Tmp);
146
164994f5 147 if (F.Type == "gz" || F.Type == "bz2" || F.Type == "lzma" || F.Type == "tar")
b2e465d6
AL
148 {
149 Pos = Tmp-1;
150 continue;
151 }
152
153 break;
154 }
155
36f610f1
AL
156 List.push_back(F);
157 }
158
159 return true;
160}
161 /*}}}*/
7a9f09bd
MV
162// SrcRecordParser::~SrcRecordParser - Destructor /*{{{*/
163// ---------------------------------------------------------------------
164/* */
165debSrcRecordParser::~debSrcRecordParser()
166{
167 delete[] Buffer;
168}
169 /*}}}*/