]>
git.saurik.com Git - apt.git/blob - apt-pkg/deb/deblistparser.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: deblistparser.cc,v 1.15 1999/02/01 02:22:11 jgg Exp $
4 /* ######################################################################
6 Package Cache Generator - Generator for the cache structure.
8 This builds the cache structure from the abstract package list parser.
10 ##################################################################### */
12 // Include Files /*{{{*/
13 #include <apt-pkg/deblistparser.h>
14 #include <apt-pkg/error.h>
15 #include <apt-pkg/configuration.h>
16 #include <apt-pkg/strutl.h>
21 // ListParser::debListParser - Constructor /*{{{*/
22 // ---------------------------------------------------------------------
24 debListParser::debListParser(FileFd
&File
) : Tags(File
)
28 // ListParser::UniqFindTagWrite - Find the tag and write a unq string /*{{{*/
29 // ---------------------------------------------------------------------
31 unsigned long debListParser::UniqFindTagWrite(const char *Tag
)
35 if (Section
.Find(Tag
,Start
,Stop
) == false)
37 return WriteUniqString(Start
,Stop
- Start
);
40 // ListParser::Package - Return the package name /*{{{*/
41 // ---------------------------------------------------------------------
42 /* This is to return the name of the package this section describes */
43 string
debListParser::Package()
45 string Result
= Section
.FindS("Package");
46 if (Result
.empty() == true)
47 _error
->Error("Encoutered a section with no Package: header");
51 // ListParser::Version - Return the version string /*{{{*/
52 // ---------------------------------------------------------------------
53 /* This is to return the string describing the version in debian form,
54 epoch:upstream-release. If this returns the blank string then the
55 entry is assumed to only describe package properties */
56 string
debListParser::Version()
58 return Section
.FindS("Version");
61 // ListParser::NewVersion - Fill in the version structure /*{{{*/
62 // ---------------------------------------------------------------------
64 bool debListParser::NewVersion(pkgCache::VerIterator Ver
)
67 Ver
->Section
= UniqFindTagWrite("Section");
68 Ver
->Arch
= UniqFindTagWrite("Architecture");
71 Ver
->Size
= (unsigned)Section
.FindI("Size");
73 // Unpacked Size (in K)
74 Ver
->InstalledSize
= (unsigned)Section
.FindI("Installed-Size");
75 Ver
->InstalledSize
*= 1024;
80 if (Section
.Find("Priority",Start
,Stop
) == true)
82 WordList PrioList
[] = {{"important",pkgCache::State::Important
},
83 {"required",pkgCache::State::Required
},
84 {"standard",pkgCache::State::Standard
},
85 {"optional",pkgCache::State::Optional
},
86 {"extra",pkgCache::State::Extra
}};
87 if (GrabWord(string(Start
,Stop
-Start
),PrioList
,
88 _count(PrioList
),Ver
->Priority
) == false)
89 return _error
->Error("Malformed Priority line");
92 if (ParseDepends(Ver
,"Depends",pkgCache::Dep::Depends
) == false)
94 if (ParseDepends(Ver
,"Pre-Depends",pkgCache::Dep::PreDepends
) == false)
96 if (ParseDepends(Ver
,"Suggests",pkgCache::Dep::Suggests
) == false)
98 if (ParseDepends(Ver
,"Recommends",pkgCache::Dep::Recommends
) == false)
100 if (ParseDepends(Ver
,"Conflicts",pkgCache::Dep::Conflicts
) == false)
102 if (ParseDepends(Ver
,"Replaces",pkgCache::Dep::Replaces
) == false)
105 if (ParseProvides(Ver
) == false)
111 // ListParser::UsePackage - Update a package structure /*{{{*/
112 // ---------------------------------------------------------------------
113 /* This is called to update the package with any new information
114 that might be found in the section */
115 bool debListParser::UsePackage(pkgCache::PkgIterator Pkg
,
116 pkgCache::VerIterator Ver
)
118 if (Pkg
->Section
== 0)
119 Pkg
->Section
= UniqFindTagWrite("Section");
120 if (Section
.FindFlag("Essential",Pkg
->Flags
,pkgCache::Flag::Essential
) == false)
122 if (Section
.FindFlag("Immediate-Configure",Pkg
->Flags
,pkgCache::Flag::ImmediateConf
) == false)
124 if (ParseStatus(Pkg
,Ver
) == false)
129 // ListParser::ParseStatus - Parse the status field /*{{{*/
130 // ---------------------------------------------------------------------
131 /* Status lines are of the form,
132 Status: want flag status
133 want = unknown, install, hold, deinstall, purge
134 flag = ok, reinstreq, hold, hold-reinstreq
135 status = not-installed, unpacked, half-configured, uninstalled,
136 half-installed, config-files, post-inst-failed,
137 removal-failed, installed
139 Some of the above are obsolete (I think?) flag = hold-* and
140 status = post-inst-failed, removal-failed at least.
142 bool debListParser::ParseStatus(pkgCache::PkgIterator Pkg
,
143 pkgCache::VerIterator Ver
)
147 if (Section
.Find("Status",Start
,Stop
) == false)
150 // Isolate the first word
151 const char *I
= Start
;
152 for(; I
< Stop
&& *I
!= ' '; I
++);
153 if (I
>= Stop
|| *I
!= ' ')
154 return _error
->Error("Malformed Status line");
156 // Process the want field
157 WordList WantList
[] = {{"unknown",pkgCache::State::Unknown
},
158 {"install",pkgCache::State::Install
},
159 {"hold",pkgCache::State::Hold
},
160 {"deinstall",pkgCache::State::DeInstall
},
161 {"purge",pkgCache::State::Purge
}};
162 if (GrabWord(string(Start
,I
-Start
),WantList
,
163 _count(WantList
),Pkg
->SelectedState
) == false)
164 return _error
->Error("Malformed 1st word in the Status line");
166 // Isloate the next word
169 for(; I
< Stop
&& *I
!= ' '; I
++);
170 if (I
>= Stop
|| *I
!= ' ')
171 return _error
->Error("Malformed status line, no 2nd word");
173 // Process the flag field
174 WordList FlagList
[] = {{"ok",pkgCache::State::Ok
},
175 {"reinstreq",pkgCache::State::ReInstReq
},
176 {"hold",pkgCache::State::HoldInst
},
177 {"hold-reinstreq",pkgCache::State::HoldReInstReq
}};
178 if (GrabWord(string(Start
,I
-Start
),FlagList
,
179 _count(FlagList
),Pkg
->InstState
) == false)
180 return _error
->Error("Malformed 2nd word in the Status line");
182 // Isloate the last word
185 for(; I
< Stop
&& *I
!= ' '; I
++);
187 return _error
->Error("Malformed Status line, no 3rd word");
189 // Process the flag field
190 WordList StatusList
[] = {{"not-installed",pkgCache::State::NotInstalled
},
191 {"unpacked",pkgCache::State::UnPacked
},
192 {"half-configured",pkgCache::State::HalfConfigured
},
193 {"installed",pkgCache::State::Installed
},
194 {"uninstalled",pkgCache::State::UnInstalled
},
195 {"half-installed",pkgCache::State::HalfInstalled
},
196 {"config-files",pkgCache::State::ConfigFiles
},
197 {"post-inst-failed",pkgCache::State::HalfConfigured
},
198 {"removal-failed",pkgCache::State::HalfInstalled
}};
199 if (GrabWord(string(Start
,I
-Start
),StatusList
,
200 _count(StatusList
),Pkg
->CurrentState
) == false)
201 return _error
->Error("Malformed 3rd word in the Status line");
203 /* A Status line marks the package as indicating the current
204 version as well. Only if it is actually installed.. Otherwise
205 the interesting dpkg handling of the status file creates bogus
207 if (!(Pkg
->CurrentState
== pkgCache::State::NotInstalled
||
208 Pkg
->CurrentState
== pkgCache::State::ConfigFiles
))
210 if (Ver
.end() == true)
211 _error
->Warning("Encountered status field in a non-version description");
213 Pkg
->CurrentVer
= Ver
.Index();
219 // ListParser::ParseDepends - Parse a dependency element /*{{{*/
220 // ---------------------------------------------------------------------
221 /* This parses the dependency elements out of a standard string in place,
223 const char *debListParser::ParseDepends(const char *Start
,const char *Stop
,
224 string
&Package
,string
&Ver
,
227 // Strip off leading space
228 for (;Start
!= Stop
&& isspace(*Start
) != 0; Start
++);
230 // Parse off the package name
231 const char *I
= Start
;
232 for (;I
!= Stop
&& isspace(*I
) == 0 && *I
!= '(' && *I
!= ')' &&
233 *I
!= ',' && *I
!= '|'; I
++);
236 if (I
!= Stop
&& *I
== ')')
242 // Stash the package name
243 Package
.assign(Start
,I
- Start
);
245 // Skip white space to the '('
246 for (;I
!= Stop
&& isspace(*I
) != 0 ; I
++);
249 if (I
!= Stop
&& *I
== '(')
252 for (I
++; I
!= Stop
&& isspace(*I
) != 0 ; I
++);
256 // Determine the operator
264 Op
= pkgCache::Dep::LessEq
;
271 Op
= pkgCache::Dep::Less
;
275 // < is the same as <= and << is really Cs < for some reason
276 Op
= pkgCache::Dep::LessEq
;
284 Op
= pkgCache::Dep::GreaterEq
;
291 Op
= pkgCache::Dep::Greater
;
295 // > is the same as >= and >> is really Cs > for some reason
296 Op
= pkgCache::Dep::GreaterEq
;
300 Op
= pkgCache::Dep::Equals
;
304 // HACK around bad package definitions
306 Op
= pkgCache::Dep::Equals
;
311 for (;I
!= Stop
&& isspace(*I
) != 0; I
++);
313 for (;I
!= Stop
&& *I
!= ')'; I
++);
314 if (I
== Stop
|| Start
== I
)
317 Ver
= string(Start
,I
-Start
);
323 Op
= pkgCache::Dep::NoOp
;
327 for (;I
!= Stop
&& isspace(*I
) != 0; I
++);
328 if (I
!= Stop
&& *I
== '|')
329 Op
|= pkgCache::Dep::Or
;
331 if (I
== Stop
|| *I
== ',' || *I
== '|')
334 for (I
++; I
!= Stop
&& isspace(*I
) != 0; I
++);
341 // ListParser::ParseDepends - Parse a dependency list /*{{{*/
342 // ---------------------------------------------------------------------
343 /* This is the higher level depends parser. It takes a tag and generates
344 a complete depends tree for the given version. */
345 bool debListParser::ParseDepends(pkgCache::VerIterator Ver
,
346 const char *Tag
,unsigned int Type
)
350 if (Section
.Find(Tag
,Start
,Stop
) == false)
359 Start
= ParseDepends(Start
,Stop
,Package
,Version
,Op
);
361 return _error
->Error("Problem parsing dependency %s",Tag
);
363 if (NewDepends(Ver
,Package
,Version
,Op
,Type
) == false)
371 // ListParser::ParseProvides - Parse the provides list /*{{{*/
372 // ---------------------------------------------------------------------
374 bool debListParser::ParseProvides(pkgCache::VerIterator Ver
)
378 if (Section
.Find("Provides",Start
,Stop
) == false)
387 Start
= ParseDepends(Start
,Stop
,Package
,Version
,Op
);
389 return _error
->Error("Problem parsing Provides line");
390 if (Op
!= pkgCache::Dep::NoOp
)
391 return _error
->Error("Malformed provides line");
393 if (NewProvides(Ver
,Package
,Version
) == false)
403 // ListParser::GrabWord - Matches a word and returns /*{{{*/
404 // ---------------------------------------------------------------------
405 /* Looks for a word in a list of words - for ParseStatus */
406 bool debListParser::GrabWord(string Word
,WordList
*List
,int Count
,
409 for (int C
= 0; C
!= Count
; C
++)
411 if (strcasecmp(Word
.c_str(),List
[C
].Str
) == 0)
420 // ListParser::Step - Move to the next section in the file /*{{{*/
421 // ---------------------------------------------------------------------
422 /* This has to be carefull to only process the correct architecture */
423 bool debListParser::Step()
425 iOffset
= Tags
.Offset();
426 string Arch
= _config
->Find("APT::architecture");
427 while (Tags
.Step(Section
) == true)
429 /* See if this is the correct Architecture, if it isnt then we
430 drop the whole section */
433 if (Section
.Find("Architecture",Start
,Stop
) == false)
436 if (stringcmp(Start
,Stop
,Arch
.begin(),Arch
.end()) == 0)
439 if (stringcmp(Start
,Stop
,"all") == 0)
442 iOffset
= Tags
.Offset();
447 // ListParser::LoadReleaseInfo - Load the release information /*{{{*/
448 // ---------------------------------------------------------------------
450 bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator FileI
,
453 pkgTagFile
Tags(File
);
454 pkgTagSection Section
;
455 if (Tags
.Step(Section
) == false)
460 if (Section
.Find("Archive",Start
,Stop
) == true)
461 FileI
->Archive
= WriteUniqString(Start
,Stop
- Start
);
462 if (Section
.Find("Component",Start
,Stop
) == true)
463 FileI
->Component
= WriteUniqString(Start
,Stop
- Start
);
464 if (Section
.Find("Version",Start
,Stop
) == true)
465 FileI
->Version
= WriteUniqString(Start
,Stop
- Start
);
466 if (Section
.Find("Origin",Start
,Stop
) == true)
467 FileI
->Origin
= WriteUniqString(Start
,Stop
- Start
);
468 if (Section
.Find("Label",Start
,Stop
) == true)
469 FileI
->Label
= WriteUniqString(Start
,Stop
- Start
);
470 if (Section
.Find("Architecture",Start
,Stop
) == true)
471 FileI
->Architecture
= WriteUniqString(Start
,Stop
- Start
);
473 if (Section
.FindFlag("NotAutomatic",FileI
->Flags
,
474 pkgCache::Flag::NotAutomatic
) == false)
475 _error
->Warning("Bad NotAutomatic flag");
477 return !_error
->PendingError();