]> git.saurik.com Git - apt.git/blame - apt-pkg/deb/debsrcrecords.cc
working apt-get source
[apt.git] / apt-pkg / deb / debsrcrecords.cc
CommitLineData
11e7af84
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
36375005 3// $Id: debsrcrecords.cc,v 1.3 1999/04/07 05:30:18 jgg Exp $
11e7af84
AL
4/* ######################################################################
5
6 Debian Source Package Records - Parser implementation for Debian style
7 source indexes
8
9 ##################################################################### */
10 /*}}}*/
11// Include Files /*{{{*/
12#ifdef __GNUG__
13#pragma implementation "apt-pkg/debsrcrecords.h"
14#endif
15
16#include <apt-pkg/debsrcrecords.h>
17#include <apt-pkg/error.h>
36f610f1 18#include <apt-pkg/strutl.h>
11e7af84
AL
19 /*}}}*/
20
21// SrcRecordParser::Binaries - Return the binaries field /*{{{*/
22// ---------------------------------------------------------------------
23/* This member parses the binaries field into a pair of class arrays and
24 returns a list of strings representing all of the components of the
25 binaries field. The returned array need not be freed and will be
26 reused by the next Binaries function call. */
27const char **debSrcRecordParser::Binaries()
28{
29 string Bins = Sect.FindS("Binary");
30 char *Buf = Buffer;
31 unsigned int Bin = 0;
32 if (Bins.empty() == true)
33 return 0;
34
35 // Strip any leading spaces
36 string::const_iterator Start = Bins.begin();
37 for (; Start != Bins.end() && isspace(*Start) != 0; Start++);
38
39 string::const_iterator Pos = Start;
40 while (Pos != Bins.end())
41 {
42 // Skip to the next ','
43 for (; Pos != Bins.end() && *Pos != ','; Pos++);
44
45 // Back remove spaces
46 string::const_iterator End = Pos;
47 for (; End > Start && (End[-1] == ',' || isspace(End[-1]) != 0); End--);
48
49 // Stash the string
50 memcpy(Buf,Start,End-Start);
51 StaticBinList[Bin] = Buf;
52 Bin++;
53 Buf += End-Start;
54 *Buf++ = 0;
55
56 // Advance pos
57 for (; Pos != Bins.end() && (*Pos == ',' || isspace(*Pos) != 0); Pos++);
58 Start = Pos;
59 }
60
61 StaticBinList[Bin] = 0;
62 return StaticBinList;
63}
64 /*}}}*/
36f610f1
AL
65// SrcRecordParser::Files - Return a list of files for this source /*{{{*/
66// ---------------------------------------------------------------------
67/* This parses the list of files and returns it, each file is required to have
68 a complete source package */
69bool debSrcRecordParser::Files(vector<pkgSrcRecords::File> &List)
70{
71 List.erase(List.begin(),List.end());
72
73 string Files = Sect.FindS("Files");
74 if (Files.empty() == true)
75 return false;
76
77 // Stash the / terminated directory prefix
36375005 78 string Base = Sect.FindS("Directory");
36f610f1
AL
79 if (Base.empty() == false && Base[Base.length()-1] != '/')
80 Base += '/';
36375005 81
36f610f1
AL
82 // Iterate over the entire list grabbing each triplet
83 const char *C = Files.c_str();
84 while (*C != 0)
85 {
86 pkgSrcRecords::File F;
87 string Size;
88
89 // Parse each of the elements
90 if (ParseQuoteWord(C,F.MD5Hash) == false ||
91 ParseQuoteWord(C,Size) == false ||
92 ParseQuoteWord(C,F.Path) == false)
93 return _error->Error("Error parsing file record");
94
95 // Parse the size and append the directory
96 F.Size = atoi(Size.c_str());
97 F.Path = Base + F.Path;
98 List.push_back(F);
99 }
100
101 return true;
102}
103 /*}}}*/