]>
git.saurik.com Git - apt.git/blob - apt-pkg/deb/debsrcrecords.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: debsrcrecords.cc,v 1.6 2004/03/17 05:58:54 mdz Exp $
4 /* ######################################################################
6 Debian Source Package Records - Parser implementation for Debian style
9 ##################################################################### */
11 // Include Files /*{{{*/
13 #pragma implementation "apt-pkg/debsrcrecords.h"
16 #include <apt-pkg/deblistparser.h>
17 #include <apt-pkg/debsrcrecords.h>
18 #include <apt-pkg/error.h>
19 #include <apt-pkg/strutl.h>
20 #include <apt-pkg/configuration.h>
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
28 reused by the next Binaries function call. This function is commonly
29 used during scanning to find the right package */
30 const char **debSrcRecordParser::Binaries()
32 // This should use Start/Stop too, it is supposed to be efficient after all.
33 string Bins
= Sect
.FindS("Binary");
34 if (Bins
.empty() == true || Bins
.length() >= 102400)
37 // Workaround for #236688. Only allocate a new buffer if the field
38 // is large, to avoid a performance penalty
41 if (Bins
.length() > sizeof(Buffer
))
43 BigBuf
= new char[Bins
.length()];
51 strcpy(Buf
,Bins
.c_str());
52 if (TokSplitString(',',Buf
,StaticBinList
,
53 sizeof(StaticBinList
)/sizeof(StaticBinList
[0])) == false)
62 return (const char **)StaticBinList
;
65 // SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/
66 // ---------------------------------------------------------------------
67 /* This member parses the build-depends information and returns a list of
68 package/version records representing the build dependency. The returned
69 array need not be freed and will be reused by the next call to this
71 bool debSrcRecordParser::BuildDepends(vector
<pkgSrcRecords::Parser::BuildDepRec
> &BuildDeps
, bool ArchOnly
)
74 const char *Start
, *Stop
;
76 const char *fields
[] = {"Build-Depends",
77 "Build-Depends-Indep",
79 "Build-Conflicts-Indep"};
83 for (I
= 0; I
< 4; I
++)
85 if (ArchOnly
&& (I
== 1 || I
== 3))
88 if (Sect
.Find(fields
[I
], Start
, Stop
) == false)
93 Start
= debListParser::ParseDepends(Start
, Stop
,
94 rec
.Package
,rec
.Version
,rec
.Op
,true);
97 return _error
->Error("Problem parsing dependency: %s", fields
[I
]);
100 if (rec
.Package
!= "")
101 BuildDeps
.push_back(rec
);
111 // SrcRecordParser::Files - Return a list of files for this source /*{{{*/
112 // ---------------------------------------------------------------------
113 /* This parses the list of files and returns it, each file is required to have
114 a complete source package */
115 bool debSrcRecordParser::Files(vector
<pkgSrcRecords::File
> &List
)
117 List
.erase(List
.begin(),List
.end());
119 string Files
= Sect
.FindS("Files");
120 if (Files
.empty() == true)
123 // Stash the / terminated directory prefix
124 string Base
= Sect
.FindS("Directory");
125 if (Base
.empty() == false && Base
[Base
.length()-1] != '/')
128 // Iterate over the entire list grabbing each triplet
129 const char *C
= Files
.c_str();
132 pkgSrcRecords::File F
;
135 // Parse each of the elements
136 if (ParseQuoteWord(C
,F
.MD5Hash
) == false ||
137 ParseQuoteWord(C
,Size
) == false ||
138 ParseQuoteWord(C
,F
.Path
) == false)
139 return _error
->Error("Error parsing file record");
141 // Parse the size and append the directory
142 F
.Size
= atoi(Size
.c_str());
143 F
.Path
= Base
+ F
.Path
;
145 // Try to guess what sort of file it is we are getting.
146 string::size_type Pos
= F
.Path
.length()-1;
149 string::size_type Tmp
= F
.Path
.rfind('.',Pos
);
150 if (Tmp
== string::npos
)
152 F
.Type
= string(F
.Path
,Tmp
+1,Pos
-Tmp
);
154 if (F
.Type
== "gz" || F
.Type
== "bz2")