]>
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>
17 #include <apt-pkg/aptconfiguration.h>
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
27 reused by the next Binaries function call. This function is commonly
28 used during scanning to find the right package */
29 const char **debSrcRecordParser::Binaries()
31 // This should use Start/Stop too, it is supposed to be efficient after all.
32 string Bins
= Sect
.FindS("Binary");
33 if (Bins
.empty() == true || Bins
.length() >= 102400)
36 if (Bins
.length() >= BufSize
)
39 // allocate new size based on buffer (but never smaller than 4000)
40 BufSize
= max((unsigned int)4000, max((unsigned int)Bins
.length()+1,2*BufSize
));
41 Buffer
= new char[BufSize
];
44 strcpy(Buffer
,Bins
.c_str());
45 if (TokSplitString(',',Buffer
,StaticBinList
,
46 sizeof(StaticBinList
)/sizeof(StaticBinList
[0])) == false)
49 return (const char **)StaticBinList
;
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
58 bool debSrcRecordParser::BuildDepends(vector
<pkgSrcRecords::Parser::BuildDepRec
> &BuildDeps
,
59 bool const &ArchOnly
, bool const &StripMultiArch
)
62 const char *Start
, *Stop
;
64 const char *fields
[] = {"Build-Depends",
65 "Build-Depends-Indep",
67 "Build-Conflicts-Indep"};
71 for (I
= 0; I
< 4; I
++)
73 if (ArchOnly
&& (I
== 1 || I
== 3))
76 if (Sect
.Find(fields
[I
], Start
, Stop
) == false)
81 Start
= debListParser::ParseDepends(Start
, Stop
,
82 rec
.Package
,rec
.Version
,rec
.Op
,true, StripMultiArch
);
85 return _error
->Error("Problem parsing dependency: %s", fields
[I
]);
88 if (rec
.Package
!= "")
89 BuildDeps
.push_back(rec
);
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 */
103 bool debSrcRecordParser::Files(vector
<pkgSrcRecords::File
> &List
)
105 List
.erase(List
.begin(),List
.end());
107 string Files
= Sect
.FindS("Files");
108 if (Files
.empty() == true)
111 // Stash the / terminated directory prefix
112 string Base
= Sect
.FindS("Directory");
113 if (Base
.empty() == false && Base
[Base
.length()-1] != '/')
116 std::vector
<std::string
> const compExts
= APT::Configuration::getCompressorExtensions();
118 // Iterate over the entire list grabbing each triplet
119 const char *C
= Files
.c_str();
122 pkgSrcRecords::File F
;
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");
131 // Parse the size and append the directory
132 F
.Size
= atoi(Size
.c_str());
133 F
.Path
= Base
+ F
.Path
;
135 // Try to guess what sort of file it is we are getting.
136 string::size_type Pos
= F
.Path
.length()-1;
139 string::size_type Tmp
= F
.Path
.rfind('.',Pos
);
140 if (Tmp
== string::npos
)
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")
148 F
.Type
= string(F
.Path
,Tmp
+1,Pos
-Tmp
);
150 if (std::find(compExts
.begin(), compExts
.end(), std::string(".").append(F
.Type
)) != compExts
.end() ||
166 // SrcRecordParser::~SrcRecordParser - Destructor /*{{{*/
167 // ---------------------------------------------------------------------
169 debSrcRecordParser::~debSrcRecordParser()