]>
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 const char *Start
, *End
;
36 if (Sect
.Find("Binary", Start
, End
) == false)
38 for (; isspace(*Start
) != 0; ++Start
);
42 StaticBinList
.clear();
44 Buffer
= strndup(Start
, End
- Start
);
48 char* binStartNext
= strchrnul(bin
, ',');
49 char* binEnd
= binStartNext
- 1;
50 for (; isspace(*binEnd
) != 0; --binEnd
)
52 StaticBinList
.push_back(bin
);
53 if (*binStartNext
!= ',')
56 for (bin
= binStartNext
+ 1; isspace(*bin
) != 0; ++bin
);
57 } while (*bin
!= '\0');
58 StaticBinList
.push_back(NULL
);
60 return (const char **) &StaticBinList
[0];
63 // SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/
64 // ---------------------------------------------------------------------
65 /* This member parses the build-depends information and returns a list of
66 package/version records representing the build dependency. The returned
67 array need not be freed and will be reused by the next call to this
69 bool debSrcRecordParser::BuildDepends(std::vector
<pkgSrcRecords::Parser::BuildDepRec
> &BuildDeps
,
70 bool const &ArchOnly
, bool const &StripMultiArch
)
73 const char *Start
, *Stop
;
75 const char *fields
[] = {"Build-Depends",
76 "Build-Depends-Indep",
78 "Build-Conflicts-Indep"};
82 for (I
= 0; I
< 4; I
++)
84 if (ArchOnly
&& (I
== 1 || I
== 3))
87 if (Sect
.Find(fields
[I
], Start
, Stop
) == false)
92 Start
= debListParser::ParseDepends(Start
, Stop
,
93 rec
.Package
,rec
.Version
,rec
.Op
,true, StripMultiArch
);
96 return _error
->Error("Problem parsing dependency: %s", fields
[I
]);
99 if (rec
.Package
!= "")
100 BuildDeps
.push_back(rec
);
110 // SrcRecordParser::Files - Return a list of files for this source /*{{{*/
111 // ---------------------------------------------------------------------
112 /* This parses the list of files and returns it, each file is required to have
113 a complete source package */
114 bool debSrcRecordParser::Files(std::vector
<pkgSrcRecords::File
> &List
)
116 List
.erase(List
.begin(),List
.end());
118 string Files
= Sect
.FindS("Files");
119 if (Files
.empty() == true)
122 // Stash the / terminated directory prefix
123 string Base
= Sect
.FindS("Directory");
124 if (Base
.empty() == false && Base
[Base
.length()-1] != '/')
127 std::vector
<std::string
> const compExts
= APT::Configuration::getCompressorExtensions();
129 // Iterate over the entire list grabbing each triplet
130 const char *C
= Files
.c_str();
133 pkgSrcRecords::File F
;
136 // Parse each of the elements
137 if (ParseQuoteWord(C
,F
.MD5Hash
) == false ||
138 ParseQuoteWord(C
,Size
) == false ||
139 ParseQuoteWord(C
,F
.Path
) == false)
140 return _error
->Error("Error parsing file record");
142 // Parse the size and append the directory
143 F
.Size
= atoi(Size
.c_str());
144 F
.Path
= Base
+ F
.Path
;
146 // Try to guess what sort of file it is we are getting.
147 string::size_type Pos
= F
.Path
.length()-1;
150 string::size_type Tmp
= F
.Path
.rfind('.',Pos
);
151 if (Tmp
== string::npos
)
153 if (F
.Type
== "tar") {
154 // source v3 has extension 'debian.tar.*' instead of 'diff.*'
155 if (string(F
.Path
, Tmp
+1, Pos
-Tmp
) == "debian")
159 F
.Type
= string(F
.Path
,Tmp
+1,Pos
-Tmp
);
161 if (std::find(compExts
.begin(), compExts
.end(), std::string(".").append(F
.Type
)) != compExts
.end() ||
177 // SrcRecordParser::~SrcRecordParser - Destructor /*{{{*/
178 // ---------------------------------------------------------------------
180 debSrcRecordParser::~debSrcRecordParser()