]>
git.saurik.com Git - apt.git/blob - apt-pkg/deb/debsrcrecords.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: debsrcrecords.cc,v 1.4 2001/02/20 07:03:17 jgg Exp $
4 /* ######################################################################
6 Debian Source Package Records - Parser implementation for Debian style
9 ##################################################################### */
11 // Include Files /*{{{*/
13 #pragma implementation "apt-pkg/debsrcrecords.h"
16 #include <apt-pkg/deblistparser.h>
17 #include <apt-pkg/debsrcrecords.h>
18 #include <apt-pkg/error.h>
19 #include <apt-pkg/strutl.h>
20 #include <apt-pkg/configuration.h>
23 // SrcRecordParser::Binaries - Return the binaries field /*{{{*/
24 // ---------------------------------------------------------------------
25 /* This member parses the binaries field into a pair of class arrays and
26 returns a list of strings representing all of the components of the
27 binaries field. The returned array need not be freed and will be
28 reused by the next Binaries function call. This function is commonly
29 used during scanning to find the right package */
30 const char **debSrcRecordParser::Binaries()
32 // This should use Start/Stop too, it is supposed to be efficient after all.
33 string Bins
= Sect
.FindS("Binary");
34 if (Bins
.empty() == true || Bins
.length() >= sizeof(Buffer
))
37 strcpy(Buffer
,Bins
.c_str());
38 if (TokSplitString(',',Buffer
,StaticBinList
,
39 sizeof(StaticBinList
)/sizeof(StaticBinList
[0])) == false)
41 return (const char **)StaticBinList
;
44 // SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/
45 // ---------------------------------------------------------------------
46 /* This member parses the build-depends information and returns a list of
47 package/version records representing the build dependency. The returned
48 array need not be freed and will be reused by the next call to this
50 bool debSrcRecordParser::BuildDepends(vector
<pkgSrcRecords::Parser::BuildDepRec
> &BuildDeps
)
53 const char *Start
, *Stop
;
55 const char *fields
[] = {"Build-Depends",
56 "Build-Depends-Indep",
58 "Build-Conflicts-Indep"};
62 for (I
= 0; I
< 4; I
++)
64 if (Sect
.Find(fields
[I
], Start
, Stop
) == false)
69 Start
= debListParser::ParseDepends(Start
, Stop
,
70 rec
.Package
,rec
.Version
,rec
.Op
,true);
73 return _error
->Error("Problem parsing dependency: %s", fields
[I
]);
76 if (rec
.Package
!= "")
77 BuildDeps
.push_back(rec
);
87 // SrcRecordParser::Files - Return a list of files for this source /*{{{*/
88 // ---------------------------------------------------------------------
89 /* This parses the list of files and returns it, each file is required to have
90 a complete source package */
91 bool debSrcRecordParser::Files(vector
<pkgSrcRecords::File
> &List
)
93 List
.erase(List
.begin(),List
.end());
95 string Files
= Sect
.FindS("Files");
96 if (Files
.empty() == true)
99 // Stash the / terminated directory prefix
100 string Base
= Sect
.FindS("Directory");
101 if (Base
.empty() == false && Base
[Base
.length()-1] != '/')
104 // Iterate over the entire list grabbing each triplet
105 const char *C
= Files
.c_str();
108 pkgSrcRecords::File F
;
111 // Parse each of the elements
112 if (ParseQuoteWord(C
,F
.MD5Hash
) == false ||
113 ParseQuoteWord(C
,Size
) == false ||
114 ParseQuoteWord(C
,F
.Path
) == false)
115 return _error
->Error("Error parsing file record");
117 // Parse the size and append the directory
118 F
.Size
= atoi(Size
.c_str());
119 F
.Path
= Base
+ F
.Path
;
121 // Try to guess what sort of file it is we are getting.
122 string::size_type Pos
= F
.Path
.length()-1;
125 string::size_type Tmp
= F
.Path
.rfind('.',Pos
);
126 if (Tmp
== string::npos
)
128 F
.Type
= string(F
.Path
,Tmp
+1,Pos
-Tmp
);
130 if (F
.Type
== "gz" || F
.Type
== "bz2")