]>
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 /*{{{*/
12 #include <apt-pkg/deblistparser.h>
13 #include <apt-pkg/debsrcrecords.h>
14 #include <apt-pkg/error.h>
15 #include <apt-pkg/strutl.h>
16 #include <apt-pkg/configuration.h>
19 // SrcRecordParser::Binaries - Return the binaries field /*{{{*/
20 // ---------------------------------------------------------------------
21 /* This member parses the binaries field into a pair of class arrays and
22 returns a list of strings representing all of the components of the
23 binaries field. The returned array need not be freed and will be
24 reused by the next Binaries function call. This function is commonly
25 used during scanning to find the right package */
26 const char **debSrcRecordParser::Binaries()
28 // This should use Start/Stop too, it is supposed to be efficient after all.
29 string Bins
= Sect
.FindS("Binary");
30 if (Bins
.empty() == true || Bins
.length() >= 102400)
33 // Workaround for #236688. Only allocate a new buffer if the field
34 // is large, to avoid a performance penalty
37 if (Bins
.length() > sizeof(Buffer
))
39 BigBuf
= new char[Bins
.length()];
47 strcpy(Buf
,Bins
.c_str());
48 if (TokSplitString(',',Buf
,StaticBinList
,
49 sizeof(StaticBinList
)/sizeof(StaticBinList
[0])) == false)
58 return (const char **)StaticBinList
;
61 // SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/
62 // ---------------------------------------------------------------------
63 /* This member parses the build-depends information and returns a list of
64 package/version records representing the build dependency. The returned
65 array need not be freed and will be reused by the next call to this
67 bool debSrcRecordParser::BuildDepends(vector
<pkgSrcRecords::Parser::BuildDepRec
> &BuildDeps
, bool ArchOnly
)
70 const char *Start
, *Stop
;
72 const char *fields
[] = {"Build-Depends",
73 "Build-Depends-Indep",
75 "Build-Conflicts-Indep"};
79 for (I
= 0; I
< 4; I
++)
81 if (ArchOnly
&& (I
== 1 || I
== 3))
84 if (Sect
.Find(fields
[I
], Start
, Stop
) == false)
89 Start
= debListParser::ParseDepends(Start
, Stop
,
90 rec
.Package
,rec
.Version
,rec
.Op
,true);
93 return _error
->Error("Problem parsing dependency: %s", fields
[I
]);
96 if (rec
.Package
!= "")
97 BuildDeps
.push_back(rec
);
107 // SrcRecordParser::Files - Return a list of files for this source /*{{{*/
108 // ---------------------------------------------------------------------
109 /* This parses the list of files and returns it, each file is required to have
110 a complete source package */
111 bool debSrcRecordParser::Files(vector
<pkgSrcRecords::File
> &List
)
113 List
.erase(List
.begin(),List
.end());
115 string Files
= Sect
.FindS("Files");
116 if (Files
.empty() == true)
119 // Stash the / terminated directory prefix
120 string Base
= Sect
.FindS("Directory");
121 if (Base
.empty() == false && Base
[Base
.length()-1] != '/')
124 // Iterate over the entire list grabbing each triplet
125 const char *C
= Files
.c_str();
128 pkgSrcRecords::File F
;
131 // Parse each of the elements
132 if (ParseQuoteWord(C
,F
.MD5Hash
) == false ||
133 ParseQuoteWord(C
,Size
) == false ||
134 ParseQuoteWord(C
,F
.Path
) == false)
135 return _error
->Error("Error parsing file record");
137 // Parse the size and append the directory
138 F
.Size
= atoi(Size
.c_str());
139 F
.Path
= Base
+ F
.Path
;
141 // Try to guess what sort of file it is we are getting.
142 string::size_type Pos
= F
.Path
.length()-1;
145 string::size_type Tmp
= F
.Path
.rfind('.',Pos
);
146 if (Tmp
== string::npos
)
148 F
.Type
= string(F
.Path
,Tmp
+1,Pos
-Tmp
);
150 if (F
.Type
== "gz" || F
.Type
== "bz2")