]>
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/aptconfiguration.h>
19 #include <apt-pkg/srcrecords.h>
20 #include <apt-pkg/tagfile.h>
33 // SrcRecordParser::Binaries - Return the binaries field /*{{{*/
34 // ---------------------------------------------------------------------
35 /* This member parses the binaries field into a pair of class arrays and
36 returns a list of strings representing all of the components of the
37 binaries field. The returned array need not be freed and will be
38 reused by the next Binaries function call. This function is commonly
39 used during scanning to find the right package */
40 const char **debSrcRecordParser::Binaries()
42 const char *Start
, *End
;
43 if (Sect
.Find("Binary", Start
, End
) == false)
45 for (; isspace(*Start
) != 0; ++Start
);
49 StaticBinList
.clear();
51 Buffer
= strndup(Start
, End
- Start
);
55 char* binStartNext
= strchrnul(bin
, ',');
56 char* binEnd
= binStartNext
- 1;
57 for (; isspace(*binEnd
) != 0; --binEnd
)
59 StaticBinList
.push_back(bin
);
60 if (*binStartNext
!= ',')
63 for (bin
= binStartNext
+ 1; isspace(*bin
) != 0; ++bin
)
65 } while (*bin
!= '\0');
66 StaticBinList
.push_back(NULL
);
68 return &StaticBinList
[0];
71 // SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/
72 // ---------------------------------------------------------------------
73 /* This member parses the build-depends information and returns a list of
74 package/version records representing the build dependency. The returned
75 array need not be freed and will be reused by the next call to this
77 bool debSrcRecordParser::BuildDepends(std::vector
<pkgSrcRecords::Parser::BuildDepRec
> &BuildDeps
,
78 bool const &ArchOnly
, bool const &StripMultiArch
)
81 const char *Start
, *Stop
;
83 const char *fields
[] = {"Build-Depends",
84 "Build-Depends-Indep",
86 "Build-Conflicts-Indep"};
90 for (I
= 0; I
< 4; I
++)
92 if (ArchOnly
&& (I
== 1 || I
== 3))
95 if (Sect
.Find(fields
[I
], Start
, Stop
) == false)
100 Start
= debListParser::ParseDepends(Start
, Stop
,
101 rec
.Package
,rec
.Version
,rec
.Op
,true,StripMultiArch
,true);
104 return _error
->Error("Problem parsing dependency: %s", fields
[I
]);
107 if (rec
.Package
!= "")
108 BuildDeps
.push_back(rec
);
118 // SrcRecordParser::Files - Return a list of files for this source /*{{{*/
119 // ---------------------------------------------------------------------
120 /* This parses the list of files and returns it, each file is required to have
121 a complete source package */
122 bool debSrcRecordParser::Files(std::vector
<pkgSrcRecords::File
> &List
)
124 List
.erase(List
.begin(),List
.end());
126 string Files
= Sect
.FindS("Files");
127 if (Files
.empty() == true)
130 // Stash the / terminated directory prefix
131 string Base
= Sect
.FindS("Directory");
132 if (Base
.empty() == false && Base
[Base
.length()-1] != '/')
135 std::vector
<std::string
> const compExts
= APT::Configuration::getCompressorExtensions();
137 // Iterate over the entire list grabbing each triplet
138 const char *C
= Files
.c_str();
141 pkgSrcRecords::File F
;
144 // Parse each of the elements
145 if (ParseQuoteWord(C
,F
.MD5Hash
) == false ||
146 ParseQuoteWord(C
,Size
) == false ||
147 ParseQuoteWord(C
,F
.Path
) == false)
148 return _error
->Error("Error parsing file record");
150 // Parse the size and append the directory
151 F
.Size
= atoi(Size
.c_str());
152 F
.Path
= Base
+ F
.Path
;
154 // Try to guess what sort of file it is we are getting.
155 string::size_type Pos
= F
.Path
.length()-1;
158 string::size_type Tmp
= F
.Path
.rfind('.',Pos
);
159 if (Tmp
== string::npos
)
161 if (F
.Type
== "tar") {
162 // source v3 has extension 'debian.tar.*' instead of 'diff.*'
163 if (string(F
.Path
, Tmp
+1, Pos
-Tmp
) == "debian")
167 F
.Type
= string(F
.Path
,Tmp
+1,Pos
-Tmp
);
169 if (std::find(compExts
.begin(), compExts
.end(), std::string(".").append(F
.Type
)) != compExts
.end() ||
185 // SrcRecordParser::~SrcRecordParser - Destructor /*{{{*/
186 // ---------------------------------------------------------------------
188 debSrcRecordParser::~debSrcRecordParser()
190 // was allocated via strndup()