]>
git.saurik.com Git - apt.git/blob - apt-pkg/deb/deblistparser.cc
28298aa3692daa46f49a20a4fe8114d3553ec30a
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: deblistparser.cc,v 1.1 1998/07/04 05:58:08 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 <pkglib/deblistparser.h>
14 #include <pkglib/error.h>
18 // ListParser::debListParser - Constructor /*{{{*/
19 // ---------------------------------------------------------------------
21 debListParser::debListParser(File
&File
) : Tags(File
)
26 // ListParser::FindTag - Find the tag and return a string /*{{{*/
27 // ---------------------------------------------------------------------
29 string
debListParser::FindTag(const char *Tag
)
33 if (Section
.Find(Tag
,Start
,Stop
) == false)
35 return string(Start
,Stop
- Start
);
38 // ListParser::UniqFindTagWrite - Find the tag and write a unq string /*{{{*/
39 // ---------------------------------------------------------------------
41 unsigned long debListParser::UniqFindTagWrite(const char *Tag
)
45 if (Section
.Find(Tag
,Start
,Stop
) == false)
47 return WriteUniqString(Start
,Stop
- Start
);
50 // ListParser::HandleFlag - Sets a flag variable based on a tag /*{{{*/
51 // ---------------------------------------------------------------------
52 /* This checks the tag for true/false yes/no etc */
53 bool debListParser::HandleFlag(const char *Tag
,unsigned long &Flags
,
58 if (Section
.Find(Tag
,Start
,Stop
) == false)
62 if (strncasecmp(Start
,"yes",Stop
- Start
) == 0)
64 if (strncasecmp(Start
,"true",Stop
- Start
) == 0)
66 if (strncasecmp(Start
,"no",Stop
- Start
) == 0)
68 if (strncasecmp(Start
,"false",Stop
- Start
) == 0)
72 _error
->Warning("Unknown flag value");
83 // ListParser::Package - Return the package name /*{{{*/
84 // ---------------------------------------------------------------------
85 /* This is to return the name of the package this section describes */
86 string
debListParser::Package()
88 string Result
= FindTag("Package");
89 if (Result
.empty() == true)
90 _error
->Error("Encoutered a section with no Package: header");
94 // ListParser::Version - Return the version string /*{{{*/
95 // ---------------------------------------------------------------------
96 /* This is to return the string describing the version in debian form,
97 epoch:upstream-release. If this returns the blank string then the
98 entry is assumed to only describe package properties */
99 string
debListParser::Version()
101 return FindTag("Version");
104 // ListParser::NewPackage - Fill in the package structure /*{{{*/
105 // ---------------------------------------------------------------------
106 /* This is called when a new package structure is created. It must fill
107 in the static package information. */
108 bool debListParser::NewPackage(pkgCache::PkgIterator Pkg
)
110 // Debian doesnt have anything, everything is condionally megered
114 // ListParser::NewVersion - Fill in the version structure /*{{{*/
115 // ---------------------------------------------------------------------
117 bool debListParser::NewVersion(pkgCache::VerIterator Ver
)
122 // ListParser::UsePackage - Update a package structure /*{{{*/
123 // ---------------------------------------------------------------------
124 /* This is called to update the package with any new information
125 that might be found in the section */
126 bool debListParser::UsePackage(pkgCache::PkgIterator Pkg
,
127 pkgCache::VerIterator Ver
)
129 if (Pkg
->Section
== 0)
130 if ((Pkg
->Section
= UniqFindTagWrite("Section")) == 0)
132 if (HandleFlag("Essential",Pkg
->Flags
,pkgCache::Essential
) == false)
134 if (HandleFlag("Immediate-Configure",Pkg
->Flags
,pkgCache::ImmediateConf
) == false)
136 if (ParseStatus(Pkg
,Ver
) == false)
141 // ListParser::ParseStatus - Parse the status feild /*{{{*/
142 // ---------------------------------------------------------------------
143 /* Status lines are of the form,
144 Status: want flag status
145 want = unknown, install, hold, deinstall, purge
146 flag = ok, reinstreq, hold, hold-reinstreq
147 status = not-installed, unpacked, half-configured, uninstalled,
148 half-installed, config-files, post-inst-failed,
149 removal-failed, installed
151 Some of the above are obsolete (I think?) flag = hold-* and
152 status = post-inst-failed, removal-failed at least.
154 bool debListParser::ParseStatus(pkgCache::PkgIterator Pkg
,
155 pkgCache::VerIterator Ver
)
159 if (Section
.Find("Status",Start
,Stop
) == false)
162 // Isolate the first word
163 const char *I
= Start
;
164 for(; I
< Stop
&& *I
!= ' '; I
++);
165 if (I
>= Stop
|| *I
!= ' ')
166 return _error
->Error("Malformed Status line");
168 // Process the want field
169 WordList WantList
[] = {{"unknown",pkgCache::Unknown
},
170 {"install",pkgCache::Install
},
171 {"hold",pkgCache::Hold
},
172 {"deinstall",pkgCache::DeInstall
},
173 {"purge",pkgCache::Purge
}};
174 if (GrabWord(string(Start
,I
-Start
),WantList
,
175 _count(WantList
),Pkg
->SelectedState
) == false)
176 return _error
->Error("Malformed 1st word in the Status line");
178 // Isloate the next word
181 for(; I
< Stop
&& *I
!= ' '; I
++);
182 if (I
>= Stop
|| *I
!= ' ')
183 return _error
->Error("Malformed status line, no 2nd word");
185 // Process the flag field
186 WordList FlagList
[] = {{"ok",pkgCache::Ok
},
187 {"reinstreq",pkgCache::ReInstReq
},
188 {"hold",pkgCache::HoldInst
},
189 {"hold-reinstreq",pkgCache::HoldReInstReq
}};
190 if (GrabWord(string(Start
,I
-Start
),FlagList
,
191 _count(FlagList
),Pkg
->InstState
) == false)
192 return _error
->Error("Malformed 2nd word in the Status line");
194 // Isloate the last word
197 for(; I
< Stop
&& *I
!= ' '; I
++);
199 return _error
->Error("Malformed Status line, no 3rd word");
201 // Process the flag field
202 WordList StatusList
[] = {{"not-installed",pkgCache::NotInstalled
},
203 {"unpacked",pkgCache::UnPacked
},
204 {"half-configured",pkgCache::HalfConfigured
},
205 {"installed",pkgCache::Installed
},
206 {"uninstalled",pkgCache::UnInstalled
},
207 {"half-installed",pkgCache::HalfInstalled
},
208 {"config-files",pkgCache::ConfigFiles
},
209 {"post-inst-failed",pkgCache::HalfConfigured
},
210 {"removal-failed",pkgCache::HalfInstalled
}};
211 if (GrabWord(string(Start
,I
-Start
),StatusList
,
212 _count(StatusList
),Pkg
->CurrentState
) == false)
213 return _error
->Error("Malformed 3rd word in the Status line");
215 /* A Status line marks the package as indicating the current
216 version as well. Only if it is actually installed.. Otherwise
217 the interesting dpkg handling of the status file creates bogus
219 if (!(Pkg
->CurrentState
== pkgCache::NotInstalled
||
220 Pkg
->CurrentState
== pkgCache::ConfigFiles
))
222 if (Ver
.end() == true)
223 _error
->Warning("Encountered status field in a non-version description");
225 Pkg
->CurrentVer
= Ver
.Index();
231 // ListParser::GrabWord - Matches a word and returns /*{{{*/
232 // ---------------------------------------------------------------------
233 /* Looks for a word in a list of words - for ParseStatus */
234 bool debListParser::GrabWord(string Word
,WordList
*List
,int Count
,
237 for (int C
= 0; C
!= Count
; C
++)
239 if (strcasecmp(Word
.c_str(),List
[C
].Str
) == 0)
248 // ListParser::Step - Move to the next section in the file /*{{{*/
249 // ---------------------------------------------------------------------
251 bool debListParser::Step()
253 return Tags
.Step(Section
);