]>
git.saurik.com Git - apt.git/blob - apt-pkg/deb/deblistparser.cc
97ee881830e1b6f70a2586c7ccdf79e3293aca09
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: deblistparser.cc,v 1.2 1998/07/04 22:32:17 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
)
25 // ListParser::FindTag - Find the tag and return a string /*{{{*/
26 // ---------------------------------------------------------------------
28 string
debListParser::FindTag(const char *Tag
)
32 if (Section
.Find(Tag
,Start
,Stop
) == false)
34 return string(Start
,Stop
- Start
);
37 // ListParser::FindTagI - Find the tag and return an int /*{{{*/
38 // ---------------------------------------------------------------------
40 signed long debListParser::FindTagI(const char *Tag
,signed long Default
)
44 if (Section
.Find(Tag
,Start
,Stop
) == false)
47 // Copy it into a temp buffer so we can use strtol
49 if ((unsigned)(Stop
- Start
) >= sizeof(S
))
51 strncpy(S
,Start
,Stop
-Start
);
55 signed long Result
= strtol(S
,&End
,10);
61 // ListParser::UniqFindTagWrite - Find the tag and write a unq string /*{{{*/
62 // ---------------------------------------------------------------------
64 unsigned long debListParser::UniqFindTagWrite(const char *Tag
)
68 if (Section
.Find(Tag
,Start
,Stop
) == false)
70 return WriteUniqString(Start
,Stop
- Start
);
73 // ListParser::HandleFlag - Sets a flag variable based on a tag /*{{{*/
74 // ---------------------------------------------------------------------
75 /* This checks the tag for true/false yes/no etc */
76 bool debListParser::HandleFlag(const char *Tag
,unsigned long &Flags
,
81 if (Section
.Find(Tag
,Start
,Stop
) == false)
85 if (strncasecmp(Start
,"yes",Stop
- Start
) == 0)
87 if (strncasecmp(Start
,"true",Stop
- Start
) == 0)
89 if (strncasecmp(Start
,"no",Stop
- Start
) == 0)
91 if (strncasecmp(Start
,"false",Stop
- Start
) == 0)
95 _error
->Warning("Unknown flag value");
106 // ListParser::Package - Return the package name /*{{{*/
107 // ---------------------------------------------------------------------
108 /* This is to return the name of the package this section describes */
109 string
debListParser::Package()
111 string Result
= FindTag("Package");
112 if (Result
.empty() == true)
113 _error
->Error("Encoutered a section with no Package: header");
117 // ListParser::Version - Return the version string /*{{{*/
118 // ---------------------------------------------------------------------
119 /* This is to return the string describing the version in debian form,
120 epoch:upstream-release. If this returns the blank string then the
121 entry is assumed to only describe package properties */
122 string
debListParser::Version()
124 return FindTag("Version");
127 // ListParser::NewPackage - Fill in the package structure /*{{{*/
128 // ---------------------------------------------------------------------
129 /* This is called when a new package structure is created. It must fill
130 in the static package information. */
131 bool debListParser::NewPackage(pkgCache::PkgIterator Pkg
)
133 // Debian doesnt have anything, everything is condionally megered
137 // ListParser::NewVersion - Fill in the version structure /*{{{*/
138 // ---------------------------------------------------------------------
140 bool debListParser::NewVersion(pkgCache::VerIterator Ver
)
143 if ((Ver
->Section
= UniqFindTagWrite("Section")) == 0)
144 return _error
->Warning("Missing Section tag");
147 if ((Ver
->Size
= (unsigned)FindTagI("Size")) == 0)
148 return _error
->Error("Unparsable Size field");
150 // Unpacked Size (in K)
151 if ((Ver
->InstalledSize
= (unsigned)FindTagI("Installed-Size")) == 0)
152 return _error
->Error("Unparsable Installed-Size field");
153 Ver
->InstalledSize
*= 1024;
158 if (Section
.Find("Priority",Start
,Stop
) == true)
160 WordList PrioList
[] = {{"important",pkgCache::Important
},
161 {"required",pkgCache::Required
},
162 {"standard",pkgCache::Standard
},
163 {"optional",pkgCache::Optional
},
164 {"extra",pkgCache::Extra
}};
165 if (GrabWord(string(Start
,Stop
-Start
),PrioList
,
166 _count(PrioList
),Ver
->Priority
) == false)
167 return _error
->Error("Malformed Priority line");
173 // ListParser::UsePackage - Update a package structure /*{{{*/
174 // ---------------------------------------------------------------------
175 /* This is called to update the package with any new information
176 that might be found in the section */
177 bool debListParser::UsePackage(pkgCache::PkgIterator Pkg
,
178 pkgCache::VerIterator Ver
)
180 if (Pkg
->Section
== 0)
181 if ((Pkg
->Section
= UniqFindTagWrite("Section")) == 0)
183 if (HandleFlag("Essential",Pkg
->Flags
,pkgCache::Essential
) == false)
185 if (HandleFlag("Immediate-Configure",Pkg
->Flags
,pkgCache::ImmediateConf
) == false)
187 if (ParseStatus(Pkg
,Ver
) == false)
192 // ListParser::ParseStatus - Parse the status feild /*{{{*/
193 // ---------------------------------------------------------------------
194 /* Status lines are of the form,
195 Status: want flag status
196 want = unknown, install, hold, deinstall, purge
197 flag = ok, reinstreq, hold, hold-reinstreq
198 status = not-installed, unpacked, half-configured, uninstalled,
199 half-installed, config-files, post-inst-failed,
200 removal-failed, installed
202 Some of the above are obsolete (I think?) flag = hold-* and
203 status = post-inst-failed, removal-failed at least.
205 bool debListParser::ParseStatus(pkgCache::PkgIterator Pkg
,
206 pkgCache::VerIterator Ver
)
210 if (Section
.Find("Status",Start
,Stop
) == false)
213 // Isolate the first word
214 const char *I
= Start
;
215 for(; I
< Stop
&& *I
!= ' '; I
++);
216 if (I
>= Stop
|| *I
!= ' ')
217 return _error
->Error("Malformed Status line");
219 // Process the want field
220 WordList WantList
[] = {{"unknown",pkgCache::Unknown
},
221 {"install",pkgCache::Install
},
222 {"hold",pkgCache::Hold
},
223 {"deinstall",pkgCache::DeInstall
},
224 {"purge",pkgCache::Purge
}};
225 if (GrabWord(string(Start
,I
-Start
),WantList
,
226 _count(WantList
),Pkg
->SelectedState
) == false)
227 return _error
->Error("Malformed 1st word in the Status line");
229 // Isloate the next word
232 for(; I
< Stop
&& *I
!= ' '; I
++);
233 if (I
>= Stop
|| *I
!= ' ')
234 return _error
->Error("Malformed status line, no 2nd word");
236 // Process the flag field
237 WordList FlagList
[] = {{"ok",pkgCache::Ok
},
238 {"reinstreq",pkgCache::ReInstReq
},
239 {"hold",pkgCache::HoldInst
},
240 {"hold-reinstreq",pkgCache::HoldReInstReq
}};
241 if (GrabWord(string(Start
,I
-Start
),FlagList
,
242 _count(FlagList
),Pkg
->InstState
) == false)
243 return _error
->Error("Malformed 2nd word in the Status line");
245 // Isloate the last word
248 for(; I
< Stop
&& *I
!= ' '; I
++);
250 return _error
->Error("Malformed Status line, no 3rd word");
252 // Process the flag field
253 WordList StatusList
[] = {{"not-installed",pkgCache::NotInstalled
},
254 {"unpacked",pkgCache::UnPacked
},
255 {"half-configured",pkgCache::HalfConfigured
},
256 {"installed",pkgCache::Installed
},
257 {"uninstalled",pkgCache::UnInstalled
},
258 {"half-installed",pkgCache::HalfInstalled
},
259 {"config-files",pkgCache::ConfigFiles
},
260 {"post-inst-failed",pkgCache::HalfConfigured
},
261 {"removal-failed",pkgCache::HalfInstalled
}};
262 if (GrabWord(string(Start
,I
-Start
),StatusList
,
263 _count(StatusList
),Pkg
->CurrentState
) == false)
264 return _error
->Error("Malformed 3rd word in the Status line");
266 /* A Status line marks the package as indicating the current
267 version as well. Only if it is actually installed.. Otherwise
268 the interesting dpkg handling of the status file creates bogus
270 if (!(Pkg
->CurrentState
== pkgCache::NotInstalled
||
271 Pkg
->CurrentState
== pkgCache::ConfigFiles
))
273 if (Ver
.end() == true)
274 _error
->Warning("Encountered status field in a non-version description");
276 Pkg
->CurrentVer
= Ver
.Index();
282 // ListParser::GrabWord - Matches a word and returns /*{{{*/
283 // ---------------------------------------------------------------------
284 /* Looks for a word in a list of words - for ParseStatus */
285 bool debListParser::GrabWord(string Word
,WordList
*List
,int Count
,
288 for (int C
= 0; C
!= Count
; C
++)
290 if (strcasecmp(Word
.c_str(),List
[C
].Str
) == 0)
299 // ListParser::Step - Move to the next section in the file /*{{{*/
300 // ---------------------------------------------------------------------
301 /* This has to be carefull to only process the correct architecture */
302 bool debListParser::Step()
304 while (Tags
.Step(Section
) == true)
306 /* See if this is the correct Architecture, if it isnt then we
307 drop the whole section */
310 if (Section
.Find("Architecture",Start
,Stop
) == false)
313 if (strncmp(Start
,"i386",Stop
- Start
) == 0 &&
314 strlen("i386") == (unsigned)(Stop
- Start
))
317 if (strncmp(Start
,"all",Stop
- Start
) == 0 &&
318 3 == (unsigned)(Stop
- Start
))