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