]>
Commit | Line | Data |
---|---|---|
11e7af84 AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
b2e465d6 | 3 | // $Id: debsrcrecords.cc,v 1.4 2001/02/20 07:03:17 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 | ||
b2e465d6 | 16 | #include <apt-pkg/deblistparser.h> |
11e7af84 AL |
17 | #include <apt-pkg/debsrcrecords.h> |
18 | #include <apt-pkg/error.h> | |
36f610f1 | 19 | #include <apt-pkg/strutl.h> |
b2e465d6 | 20 | #include <apt-pkg/configuration.h> |
11e7af84 AL |
21 | /*}}}*/ |
22 | ||
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 | |
b2e465d6 AL |
28 | reused by the next Binaries function call. This function is commonly |
29 | used during scanning to find the right package */ | |
11e7af84 AL |
30 | const char **debSrcRecordParser::Binaries() |
31 | { | |
b2e465d6 | 32 | // This should use Start/Stop too, it is supposed to be efficient after all. |
11e7af84 | 33 | string Bins = Sect.FindS("Binary"); |
b2e465d6 | 34 | if (Bins.empty() == true || Bins.length() >= sizeof(Buffer)) |
11e7af84 AL |
35 | return 0; |
36 | ||
b2e465d6 AL |
37 | strcpy(Buffer,Bins.c_str()); |
38 | if (TokSplitString(',',Buffer,StaticBinList, | |
39 | sizeof(StaticBinList)/sizeof(StaticBinList[0])) == false) | |
40 | return 0; | |
41 | return (const char **)StaticBinList; | |
42 | } | |
43 | /*}}}*/ | |
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 | |
49 | function */ | |
50 | bool debSrcRecordParser::BuildDepends(vector<pkgSrcRecords::Parser::BuildDepRec> &BuildDeps) | |
51 | { | |
52 | unsigned int I; | |
53 | const char *Start, *Stop; | |
54 | BuildDepRec rec; | |
55 | const char *fields[] = {"Build-Depends", | |
56 | "Build-Depends-Indep", | |
57 | "Build-Conflicts", | |
58 | "Build-Conflicts-Indep"}; | |
59 | ||
60 | BuildDeps.clear(); | |
11e7af84 | 61 | |
b2e465d6 | 62 | for (I = 0; I < 4; I++) |
11e7af84 | 63 | { |
b2e465d6 AL |
64 | if (Sect.Find(fields[I], Start, Stop) == false) |
65 | continue; | |
11e7af84 | 66 | |
b2e465d6 AL |
67 | while (1) |
68 | { | |
69 | Start = debListParser::ParseDepends(Start, Stop, | |
70 | rec.Package,rec.Version,rec.Op,true); | |
71 | ||
72 | if (Start == 0) | |
73 | return _error->Error("Problem parsing dependency: %s", fields[I]); | |
74 | rec.Type = I; | |
75 | ||
76 | if (rec.Package != "") | |
77 | BuildDeps.push_back(rec); | |
78 | ||
79 | if (Start == Stop) | |
80 | break; | |
81 | } | |
11e7af84 AL |
82 | } |
83 | ||
b2e465d6 | 84 | return true; |
11e7af84 AL |
85 | } |
86 | /*}}}*/ | |
36f610f1 AL |
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) | |
92 | { | |
93 | List.erase(List.begin(),List.end()); | |
94 | ||
95 | string Files = Sect.FindS("Files"); | |
96 | if (Files.empty() == true) | |
97 | return false; | |
98 | ||
99 | // Stash the / terminated directory prefix | |
36375005 | 100 | string Base = Sect.FindS("Directory"); |
36f610f1 AL |
101 | if (Base.empty() == false && Base[Base.length()-1] != '/') |
102 | Base += '/'; | |
36375005 | 103 | |
36f610f1 AL |
104 | // Iterate over the entire list grabbing each triplet |
105 | const char *C = Files.c_str(); | |
106 | while (*C != 0) | |
107 | { | |
108 | pkgSrcRecords::File F; | |
109 | string Size; | |
110 | ||
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"); | |
116 | ||
117 | // Parse the size and append the directory | |
118 | F.Size = atoi(Size.c_str()); | |
119 | F.Path = Base + F.Path; | |
b2e465d6 AL |
120 | |
121 | // Try to guess what sort of file it is we are getting. | |
122 | string::size_type Pos = F.Path.length()-1; | |
123 | while (1) | |
124 | { | |
125 | string::size_type Tmp = F.Path.rfind('.',Pos); | |
126 | if (Tmp == string::npos) | |
127 | break; | |
128 | F.Type = string(F.Path,Tmp+1,Pos-Tmp); | |
129 | ||
130 | if (F.Type == "gz" || F.Type == "bz2") | |
131 | { | |
132 | Pos = Tmp-1; | |
133 | continue; | |
134 | } | |
135 | ||
136 | break; | |
137 | } | |
138 | ||
36f610f1 AL |
139 | List.push_back(F); |
140 | } | |
141 | ||
142 | return true; | |
143 | } | |
144 | /*}}}*/ |