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