]>
git.saurik.com Git - apt-legacy.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 /*{{{*/
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>
25 // SrcRecordParser::Binaries - Return the binaries field /*{{{*/
26 // ---------------------------------------------------------------------
27 /* This member parses the binaries field into a pair of class arrays and
28 returns a list of strings representing all of the components of the
29 binaries field. The returned array need not be freed and will be
30 reused by the next Binaries function call. This function is commonly
31 used during scanning to find the right package */
32 const char **debSrcRecordParser::Binaries()
34 // This should use Start/Stop too, it is supposed to be efficient after all.
35 string Bins
= Sect
.FindS("Binary");
36 if (Bins
.empty() == true || Bins
.length() >= 102400)
39 if (Bins
.length() >= BufSize
)
42 // allocate new size based on buffer (but never smaller than 4000)
43 BufSize
= max((unsigned long)4000, max((unsigned long)Bins
.length()+1,2*BufSize
));
44 Buffer
= new char[BufSize
];
47 strcpy(Buffer
,Bins
.c_str());
48 if (TokSplitString(',',Buffer
,StaticBinList
,
49 sizeof(StaticBinList
)/sizeof(StaticBinList
[0])) == false)
52 return (const char **)StaticBinList
;
55 // SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/
56 // ---------------------------------------------------------------------
57 /* This member parses the build-depends information and returns a list of
58 package/version records representing the build dependency. The returned
59 array need not be freed and will be reused by the next call to this
61 bool debSrcRecordParser::BuildDepends(vector
<pkgSrcRecords::Parser::BuildDepRec
> &BuildDeps
, bool ArchOnly
)
64 const char *Start
, *Stop
;
66 const char *fields
[] = {"Build-Depends",
67 "Build-Depends-Indep",
69 "Build-Conflicts-Indep"};
73 for (I
= 0; I
< 4; I
++)
75 if (ArchOnly
&& (I
== 1 || I
== 3))
78 if (Sect
.Find(fields
[I
], Start
, Stop
) == false)
83 Start
= debListParser::ParseDepends(Start
, Stop
,
84 rec
.Package
,rec
.Version
,rec
.Op
,true);
87 return _error
->Error("Problem parsing dependency: %s", fields
[I
]);
90 if (rec
.Package
!= "")
91 BuildDeps
.push_back(rec
);
101 // SrcRecordParser::Files - Return a list of files for this source /*{{{*/
102 // ---------------------------------------------------------------------
103 /* This parses the list of files and returns it, each file is required to have
104 a complete source package */
105 bool debSrcRecordParser::Files(vector
<pkgSrcRecords::File
> &List
)
107 List
.erase(List
.begin(),List
.end());
109 string Files
= Sect
.FindS("Files");
110 if (Files
.empty() == true)
113 // Stash the / terminated directory prefix
114 string Base
= Sect
.FindS("Directory");
115 if (Base
.empty() == false && Base
[Base
.length()-1] != '/')
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 F
.Type
= string(F
.Path
,Tmp
+1,Pos
-Tmp
);
144 if (F
.Type
== "gz" || F
.Type
== "bz2")