do not pollute namespace in the headers with using (Closes: #500198)
[ntk/apt.git] / apt-pkg / deb / debsrcrecords.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: debsrcrecords.cc,v 1.6 2004/03/17 05:58:54 mdz Exp $
4 /* ######################################################################
5
6 Debian Source Package Records - Parser implementation for Debian style
7 source indexes
8
9 ##################################################################### */
10 /*}}}*/
11 // Include Files /*{{{*/
12 #include <config.h>
13
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>
20
21 using std::max;
22 /*}}}*/
23
24 using std::string;
25
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()
34 {
35 // This should use Start/Stop too, it is supposed to be efficient after all.
36 string Bins = Sect.FindS("Binary");
37 if (Bins.empty() == true || Bins.length() >= 102400)
38 return 0;
39
40 if (Bins.length() >= BufSize)
41 {
42 delete [] Buffer;
43 // allocate new size based on buffer (but never smaller than 4000)
44 BufSize = max((unsigned int)4000, max((unsigned int)Bins.length()+1,2*BufSize));
45 Buffer = new char[BufSize];
46 }
47
48 strcpy(Buffer,Bins.c_str());
49 if (TokSplitString(',',Buffer,StaticBinList,
50 sizeof(StaticBinList)/sizeof(StaticBinList[0])) == false)
51 return 0;
52
53 return (const char **)StaticBinList;
54 }
55 /*}}}*/
56 // SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/
57 // ---------------------------------------------------------------------
58 /* This member parses the build-depends information and returns a list of
59 package/version records representing the build dependency. The returned
60 array need not be freed and will be reused by the next call to this
61 function */
62 bool debSrcRecordParser::BuildDepends(std::vector<pkgSrcRecords::Parser::BuildDepRec> &BuildDeps,
63 bool const &ArchOnly, bool const &StripMultiArch)
64 {
65 unsigned int I;
66 const char *Start, *Stop;
67 BuildDepRec rec;
68 const char *fields[] = {"Build-Depends",
69 "Build-Depends-Indep",
70 "Build-Conflicts",
71 "Build-Conflicts-Indep"};
72
73 BuildDeps.clear();
74
75 for (I = 0; I < 4; I++)
76 {
77 if (ArchOnly && (I == 1 || I == 3))
78 continue;
79
80 if (Sect.Find(fields[I], Start, Stop) == false)
81 continue;
82
83 while (1)
84 {
85 Start = debListParser::ParseDepends(Start, Stop,
86 rec.Package,rec.Version,rec.Op,true, StripMultiArch);
87
88 if (Start == 0)
89 return _error->Error("Problem parsing dependency: %s", fields[I]);
90 rec.Type = I;
91
92 if (rec.Package != "")
93 BuildDeps.push_back(rec);
94
95 if (Start == Stop)
96 break;
97 }
98 }
99
100 return true;
101 }
102 /*}}}*/
103 // SrcRecordParser::Files - Return a list of files for this source /*{{{*/
104 // ---------------------------------------------------------------------
105 /* This parses the list of files and returns it, each file is required to have
106 a complete source package */
107 bool debSrcRecordParser::Files(std::vector<pkgSrcRecords::File> &List)
108 {
109 List.erase(List.begin(),List.end());
110
111 string Files = Sect.FindS("Files");
112 if (Files.empty() == true)
113 return false;
114
115 // Stash the / terminated directory prefix
116 string Base = Sect.FindS("Directory");
117 if (Base.empty() == false && Base[Base.length()-1] != '/')
118 Base += '/';
119
120 std::vector<std::string> const compExts = APT::Configuration::getCompressorExtensions();
121
122 // Iterate over the entire list grabbing each triplet
123 const char *C = Files.c_str();
124 while (*C != 0)
125 {
126 pkgSrcRecords::File F;
127 string Size;
128
129 // Parse each of the elements
130 if (ParseQuoteWord(C,F.MD5Hash) == false ||
131 ParseQuoteWord(C,Size) == false ||
132 ParseQuoteWord(C,F.Path) == false)
133 return _error->Error("Error parsing file record");
134
135 // Parse the size and append the directory
136 F.Size = atoi(Size.c_str());
137 F.Path = Base + F.Path;
138
139 // Try to guess what sort of file it is we are getting.
140 string::size_type Pos = F.Path.length()-1;
141 while (1)
142 {
143 string::size_type Tmp = F.Path.rfind('.',Pos);
144 if (Tmp == string::npos)
145 break;
146 if (F.Type == "tar") {
147 // source v3 has extension 'debian.tar.*' instead of 'diff.*'
148 if (string(F.Path, Tmp+1, Pos-Tmp) == "debian")
149 F.Type = "diff";
150 break;
151 }
152 F.Type = string(F.Path,Tmp+1,Pos-Tmp);
153
154 if (std::find(compExts.begin(), compExts.end(), std::string(".").append(F.Type)) != compExts.end() ||
155 F.Type == "tar")
156 {
157 Pos = Tmp-1;
158 continue;
159 }
160
161 break;
162 }
163
164 List.push_back(F);
165 }
166
167 return true;
168 }
169 /*}}}*/
170 // SrcRecordParser::~SrcRecordParser - Destructor /*{{{*/
171 // ---------------------------------------------------------------------
172 /* */
173 debSrcRecordParser::~debSrcRecordParser()
174 {
175 delete[] Buffer;
176 }
177 /*}}}*/