]>
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 /*{{{*/
14 #include <apt-pkg/deblistparser.h>
15 #include <apt-pkg/debsrcrecords.h>
16 #include <apt-pkg/error.h>
17 #include <apt-pkg/strutl.h>
18 #include <apt-pkg/configuration.h>
19 #include <apt-pkg/aptconfiguration.h>
26 // SrcRecordParser::Binaries - Return the binaries field /*{{{*/
27 // ---------------------------------------------------------------------
28 /* This member parses the binaries field into a pair of class arrays and
29 returns a list of strings representing all of the components of the
30 binaries field. The returned array need not be freed and will be
31 reused by the next Binaries function call. This function is commonly
32 used during scanning to find the right package */
33 const char **debSrcRecordParser::Binaries()
35 // This should use Start/Stop too, it is supposed to be efficient after all.
36 string Bins
= Sect
.FindS("Binary");
37 if (Bins
.empty() == true || Bins
.length() >= 102400)
40 if (Bins
.length() >= BufSize
)
43 // allocate new size based on buffer (but never smaller than 4000)
44 BufSize
= max((unsigned int)4000, max((unsigned int)Bins
.length()+1,2*BufSize
));
45 Buffer
= new char[BufSize
];
48 strcpy(Buffer
,Bins
.c_str());
49 if (TokSplitString(',',Buffer
,StaticBinList
,
50 sizeof(StaticBinList
)/sizeof(StaticBinList
[0])) == false)
53 return (const char **)StaticBinList
;
56 // SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/
57 // ---------------------------------------------------------------------
58 /* This member parses the build-depends information and returns a list of
59 package/version records representing the build dependency. The returned
60 array need not be freed and will be reused by the next call to this
62 bool debSrcRecordParser::BuildDepends(std::vector
<pkgSrcRecords::Parser::BuildDepRec
> &BuildDeps
,
63 bool const &ArchOnly
, bool const &StripMultiArch
)
66 const char *Start
, *Stop
;
68 const char *fields
[] = {"Build-Depends",
69 "Build-Depends-Indep",
71 "Build-Conflicts-Indep"};
75 for (I
= 0; I
< 4; I
++)
77 if (ArchOnly
&& (I
== 1 || I
== 3))
80 if (Sect
.Find(fields
[I
], Start
, Stop
) == false)
85 Start
= debListParser::ParseDepends(Start
, Stop
,
86 rec
.Package
,rec
.Version
,rec
.Op
,true, StripMultiArch
);
89 return _error
->Error("Problem parsing dependency: %s", fields
[I
]);
92 if (rec
.Package
!= "")
93 BuildDeps
.push_back(rec
);
103 // SrcRecordParser::Files - Return a list of files for this source /*{{{*/
104 // ---------------------------------------------------------------------
105 /* This parses the list of files and returns it, each file is required to have
106 a complete source package */
107 bool debSrcRecordParser::Files(std::vector
<pkgSrcRecords::File
> &List
)
109 List
.erase(List
.begin(),List
.end());
111 string Files
= Sect
.FindS("Files");
112 if (Files
.empty() == true)
115 // Stash the / terminated directory prefix
116 string Base
= Sect
.FindS("Directory");
117 if (Base
.empty() == false && Base
[Base
.length()-1] != '/')
120 std::vector
<std::string
> const compExts
= APT::Configuration::getCompressorExtensions();
122 // Iterate over the entire list grabbing each triplet
123 const char *C
= Files
.c_str();
126 pkgSrcRecords::File F
;
129 // Parse each of the elements
130 if (ParseQuoteWord(C
,F
.MD5Hash
) == false ||
131 ParseQuoteWord(C
,Size
) == false ||
132 ParseQuoteWord(C
,F
.Path
) == false)
133 return _error
->Error("Error parsing file record");
135 // Parse the size and append the directory
136 F
.Size
= atoi(Size
.c_str());
137 F
.Path
= Base
+ F
.Path
;
139 // Try to guess what sort of file it is we are getting.
140 string::size_type Pos
= F
.Path
.length()-1;
143 string::size_type Tmp
= F
.Path
.rfind('.',Pos
);
144 if (Tmp
== string::npos
)
146 if (F
.Type
== "tar") {
147 // source v3 has extension 'debian.tar.*' instead of 'diff.*'
148 if (string(F
.Path
, Tmp
+1, Pos
-Tmp
) == "debian")
152 F
.Type
= string(F
.Path
,Tmp
+1,Pos
-Tmp
);
154 if (std::find(compExts
.begin(), compExts
.end(), std::string(".").append(F
.Type
)) != compExts
.end() ||
170 // SrcRecordParser::~SrcRecordParser - Destructor /*{{{*/
171 // ---------------------------------------------------------------------
173 debSrcRecordParser::~debSrcRecordParser()