]> git.saurik.com Git - apt.git/blame - cmdline/apt-cache.cc
incorporate string-fix patch from Matthew East for LP: #370094
[apt.git] / cmdline / apt-cache.cc
CommitLineData
1164783d
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
ea7f6363 3// $Id: apt-cache.cc,v 1.72 2004/04/30 04:34:03 mdz Exp $
1164783d
AL
4/* ######################################################################
5
e1b74f61 6 apt-cache - Manages the cache files
1164783d 7
e1b74f61 8 apt-cache provides some functions fo manipulating the cache files.
b2e465d6 9 It uses the command line interface common to all the APT tools.
1164783d
AL
10
11 Returns 100 on failure, 0 on success.
12
13 ##################################################################### */
14 /*}}}*/
15// Include Files /*{{{*/
16#include <apt-pkg/error.h>
17#include <apt-pkg/pkgcachegen.h>
8efa2a3b 18#include <apt-pkg/init.h>
404ec98e 19#include <apt-pkg/progress.h>
880e9be4 20#include <apt-pkg/sourcelist.h>
08e8f724 21#include <apt-pkg/cmndline.h>
cdcc6d34 22#include <apt-pkg/strutl.h>
9dbb421f 23#include <apt-pkg/pkgrecords.h>
f8f410f5 24#include <apt-pkg/srcrecords.h>
3e94da1b 25#include <apt-pkg/version.h>
b2e465d6
AL
26#include <apt-pkg/policy.h>
27#include <apt-pkg/tagfile.h>
28#include <apt-pkg/algorithms.h>
29#include <apt-pkg/sptr.h>
30
43981212 31#include <config.h>
b2e465d6 32#include <apti18n.h>
1164783d 33
233c2b66 34#include <locale.h>
90f057fd 35#include <iostream>
cdb970c7 36#include <unistd.h>
43981212 37#include <errno.h>
9dbb421f 38#include <regex.h>
3e94da1b 39#include <stdio.h>
bd3d53ef
AL
40
41#include <iomanip>
1164783d
AL
42 /*}}}*/
43
8f312f45
AL
44using namespace std;
45
b0b4efb9 46pkgCache *GCache = 0;
af87ab54 47pkgSourceList *SrcList = 0;
b0b4efb9 48
b2e465d6
AL
49// LocalitySort - Sort a version list by package file locality /*{{{*/
50// ---------------------------------------------------------------------
51/* */
52int LocalityCompare(const void *a, const void *b)
53{
54 pkgCache::VerFile *A = *(pkgCache::VerFile **)a;
55 pkgCache::VerFile *B = *(pkgCache::VerFile **)b;
56
57 if (A == 0 && B == 0)
58 return 0;
59 if (A == 0)
60 return 1;
61 if (B == 0)
62 return -1;
63
64 if (A->File == B->File)
65 return A->Offset - B->Offset;
66 return A->File - B->File;
67}
68
69void LocalitySort(pkgCache::VerFile **begin,
70 unsigned long Count,size_t Size)
71{
72 qsort(begin,Count,Size,LocalityCompare);
73}
a52f938b
OS
74
75void LocalitySort(pkgCache::DescFile **begin,
76 unsigned long Count,size_t Size)
77{
78 qsort(begin,Count,Size,LocalityCompare);
79}
b2e465d6 80 /*}}}*/
cc718e9a
AL
81// UnMet - Show unmet dependencies /*{{{*/
82// ---------------------------------------------------------------------
83/* */
b0b4efb9 84bool UnMet(CommandLine &CmdL)
cc718e9a 85{
b0b4efb9 86 pkgCache &Cache = *GCache;
76fbce56 87 bool Important = _config->FindB("APT::Cache::Important",false);
018f1533 88
cc718e9a
AL
89 for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
90 {
91 for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++)
92 {
93 bool Header = false;
018f1533 94 for (pkgCache::DepIterator D = V.DependsList(); D.end() == false;)
cc718e9a
AL
95 {
96 // Collect or groups
97 pkgCache::DepIterator Start;
98 pkgCache::DepIterator End;
99 D.GlobOr(Start,End);
100
018f1533 101 // Skip conflicts and replaces
cc718e9a
AL
102 if (End->Type != pkgCache::Dep::PreDepends &&
103 End->Type != pkgCache::Dep::Depends &&
104 End->Type != pkgCache::Dep::Suggests &&
7146a53c 105 End->Type != pkgCache::Dep::Recommends)
cc718e9a
AL
106 continue;
107
018f1533
AL
108 // Important deps only
109 if (Important == true)
110 if (End->Type != pkgCache::Dep::PreDepends &&
7146a53c 111 End->Type != pkgCache::Dep::Depends)
018f1533
AL
112 continue;
113
cc718e9a
AL
114 // Verify the or group
115 bool OK = false;
116 pkgCache::DepIterator RealStart = Start;
117 do
118 {
119 // See if this dep is Ok
120 pkgCache::Version **VList = Start.AllTargets();
121 if (*VList != 0)
122 {
123 OK = true;
124 delete [] VList;
125 break;
126 }
127 delete [] VList;
128
129 if (Start == End)
130 break;
131 Start++;
132 }
133 while (1);
134
135 // The group is OK
136 if (OK == true)
137 continue;
138
139 // Oops, it failed..
140 if (Header == false)
b2e465d6
AL
141 ioprintf(cout,_("Package %s version %s has an unmet dep:\n"),
142 P.Name(),V.VerStr());
cc718e9a
AL
143 Header = true;
144
145 // Print out the dep type
146 cout << " " << End.DepType() << ": ";
147
148 // Show the group
149 Start = RealStart;
150 do
151 {
152 cout << Start.TargetPkg().Name();
153 if (Start.TargetVer() != 0)
154 cout << " (" << Start.CompType() << " " << Start.TargetVer() <<
155 ")";
156 if (Start == End)
157 break;
158 cout << " | ";
159 Start++;
160 }
161 while (1);
162
163 cout << endl;
164 }
165 }
166 }
167 return true;
168}
169 /*}}}*/
1164783d
AL
170// DumpPackage - Show a dump of a package record /*{{{*/
171// ---------------------------------------------------------------------
172/* */
b0b4efb9 173bool DumpPackage(CommandLine &CmdL)
ad00ae81 174{
b0b4efb9 175 pkgCache &Cache = *GCache;
e1b74f61 176 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
1164783d 177 {
e1b74f61 178 pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
1164783d
AL
179 if (Pkg.end() == true)
180 {
b2e465d6 181 _error->Warning(_("Unable to locate package %s"),*I);
1164783d
AL
182 continue;
183 }
184
185 cout << "Package: " << Pkg.Name() << endl;
b2e465d6 186 cout << "Versions: " << endl;
1164783d 187 for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++)
03e39e59
AL
188 {
189 cout << Cur.VerStr();
190 for (pkgCache::VerFileIterator Vf = Cur.FileList(); Vf.end() == false; Vf++)
a52f938b
OS
191 cout << " (" << Vf.File().FileName() << ")";
192 cout << endl;
193 for (pkgCache::DescIterator D = Cur.DescriptionList(); D.end() == false; D++)
194 {
195 cout << " Description Language: " << D.LanguageCode() << endl
196 << " File: " << D.FileList().File().FileName() << endl
197 << " MD5: " << D.md5() << endl;
198 }
b2e465d6 199 cout << endl;
03e39e59
AL
200 }
201
1164783d
AL
202 cout << endl;
203
204 cout << "Reverse Depends: " << endl;
205 for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() != true; D++)
b2e465d6
AL
206 {
207 cout << " " << D.ParentPkg().Name() << ',' << D.TargetPkg().Name();
208 if (D->Version != 0)
b1b663d1 209 cout << ' ' << DeNull(D.TargetVer()) << endl;
b2e465d6
AL
210 else
211 cout << endl;
212 }
213
1164783d
AL
214 cout << "Dependencies: " << endl;
215 for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++)
216 {
217 cout << Cur.VerStr() << " - ";
218 for (pkgCache::DepIterator Dep = Cur.DependsList(); Dep.end() != true; Dep++)
b1b663d1 219 cout << Dep.TargetPkg().Name() << " (" << (int)Dep->CompareOp << " " << DeNull(Dep.TargetVer()) << ") ";
1164783d
AL
220 cout << endl;
221 }
222
223 cout << "Provides: " << endl;
224 for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++)
225 {
226 cout << Cur.VerStr() << " - ";
227 for (pkgCache::PrvIterator Prv = Cur.ProvidesList(); Prv.end() != true; Prv++)
228 cout << Prv.ParentPkg().Name() << " ";
229 cout << endl;
8efa2a3b
AL
230 }
231 cout << "Reverse Provides: " << endl;
232 for (pkgCache::PrvIterator Prv = Pkg.ProvidesList(); Prv.end() != true; Prv++)
2d6751b9 233 cout << Prv.OwnerPkg().Name() << " " << Prv.OwnerVer().VerStr() << endl;
1164783d
AL
234 }
235
236 return true;
237}
238 /*}}}*/
239// Stats - Dump some nice statistics /*{{{*/
240// ---------------------------------------------------------------------
241/* */
b0b4efb9 242bool Stats(CommandLine &Cmd)
1164783d 243{
b0b4efb9 244 pkgCache &Cache = *GCache;
12bffed7 245 cout << _("Total package names: ") << Cache.Head().PackageCount << " (" <<
f826cfaa 246 SizeToStr(Cache.Head().PackageCount*Cache.Head().PackageSz) << ')' << endl;
b2e465d6 247
1164783d
AL
248 int Normal = 0;
249 int Virtual = 0;
250 int NVirt = 0;
251 int DVirt = 0;
252 int Missing = 0;
b2e465d6 253 pkgCache::PkgIterator I = Cache.PkgBegin();
1164783d
AL
254 for (;I.end() != true; I++)
255 {
256 if (I->VersionList != 0 && I->ProvidesList == 0)
257 {
258 Normal++;
259 continue;
260 }
261
262 if (I->VersionList != 0 && I->ProvidesList != 0)
263 {
264 NVirt++;
265 continue;
266 }
267
268 if (I->VersionList == 0 && I->ProvidesList != 0)
269 {
270 // Only 1 provides
271 if (I.ProvidesList()->NextProvides == 0)
272 {
273 DVirt++;
274 }
275 else
276 Virtual++;
277 continue;
278 }
279 if (I->VersionList == 0 && I->ProvidesList == 0)
280 {
281 Missing++;
282 continue;
283 }
284 }
db0db9fe
CP
285 cout << _(" Normal packages: ") << Normal << endl;
286 cout << _(" Pure virtual packages: ") << Virtual << endl;
287 cout << _(" Single virtual packages: ") << DVirt << endl;
288 cout << _(" Mixed virtual packages: ") << NVirt << endl;
b2e465d6 289 cout << _(" Missing: ") << Missing << endl;
1164783d 290
db0db9fe 291 cout << _("Total distinct versions: ") << Cache.Head().VersionCount << " (" <<
f826cfaa 292 SizeToStr(Cache.Head().VersionCount*Cache.Head().VersionSz) << ')' << endl;
12bffed7 293 cout << _("Total distinct descriptions: ") << Cache.Head().DescriptionCount << " (" <<
a52f938b 294 SizeToStr(Cache.Head().DescriptionCount*Cache.Head().DescriptionSz) << ')' << endl;
db0db9fe 295 cout << _("Total dependencies: ") << Cache.Head().DependsCount << " (" <<
f826cfaa
AL
296 SizeToStr(Cache.Head().DependsCount*Cache.Head().DependencySz) << ')' << endl;
297
db0db9fe 298 cout << _("Total ver/file relations: ") << Cache.Head().VerFileCount << " (" <<
a7e66b17 299 SizeToStr(Cache.Head().VerFileCount*Cache.Head().VerFileSz) << ')' << endl;
a52f938b
OS
300 cout << _("Total Desc/File relations: ") << Cache.Head().DescFileCount << " (" <<
301 SizeToStr(Cache.Head().DescFileCount*Cache.Head().DescFileSz) << ')' << endl;
db0db9fe 302 cout << _("Total Provides mappings: ") << Cache.Head().ProvidesCount << " (" <<
a7e66b17 303 SizeToStr(Cache.Head().ProvidesCount*Cache.Head().ProvidesSz) << ')' << endl;
f826cfaa
AL
304
305 // String list stats
306 unsigned long Size = 0;
307 unsigned long Count = 0;
308 for (pkgCache::StringItem *I = Cache.StringItemP + Cache.Head().StringList;
309 I!= Cache.StringItemP; I = Cache.StringItemP + I->NextItem)
310 {
311 Count++;
b2e465d6 312 Size += strlen(Cache.StrP + I->String) + 1;
f826cfaa 313 }
db0db9fe 314 cout << _("Total globbed strings: ") << Count << " (" << SizeToStr(Size) << ')' << endl;
b2e465d6
AL
315
316 unsigned long DepVerSize = 0;
317 for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
318 {
319 for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++)
320 {
321 for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++)
322 {
323 if (D->Version != 0)
324 DepVerSize += strlen(D.TargetVer()) + 1;
325 }
326 }
327 }
db0db9fe 328 cout << _("Total dependency version space: ") << SizeToStr(DepVerSize) << endl;
b2e465d6 329
f826cfaa
AL
330 unsigned long Slack = 0;
331 for (int I = 0; I != 7; I++)
332 Slack += Cache.Head().Pools[I].ItemSize*Cache.Head().Pools[I].Count;
db0db9fe 333 cout << _("Total slack space: ") << SizeToStr(Slack) << endl;
f826cfaa
AL
334
335 unsigned long Total = 0;
336 Total = Slack + Size + Cache.Head().DependsCount*Cache.Head().DependencySz +
337 Cache.Head().VersionCount*Cache.Head().VersionSz +
a7e66b17
AL
338 Cache.Head().PackageCount*Cache.Head().PackageSz +
339 Cache.Head().VerFileCount*Cache.Head().VerFileSz +
340 Cache.Head().ProvidesCount*Cache.Head().ProvidesSz;
db0db9fe 341 cout << _("Total space accounted for: ") << SizeToStr(Total) << endl;
f826cfaa 342
83d89a9f
AL
343 return true;
344}
345 /*}}}*/
1164783d
AL
346// Dump - show everything /*{{{*/
347// ---------------------------------------------------------------------
b2e465d6 348/* This is worthless except fer debugging things */
b0b4efb9 349bool Dump(CommandLine &Cmd)
1164783d 350{
b0b4efb9 351 pkgCache &Cache = *GCache;
b2e465d6
AL
352 cout << "Using Versioning System: " << Cache.VS->Label << endl;
353
1164783d
AL
354 for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
355 {
356 cout << "Package: " << P.Name() << endl;
357 for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++)
358 {
359 cout << " Version: " << V.VerStr() << endl;
360 cout << " File: " << V.FileList().File().FileName() << endl;
361 for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++)
076d01b0
AL
362 cout << " Depends: " << D.TargetPkg().Name() << ' ' <<
363 DeNull(D.TargetVer()) << endl;
a52f938b
OS
364 for (pkgCache::DescIterator D = V.DescriptionList(); D.end() == false; D++)
365 {
366 cout << " Description Language: " << D.LanguageCode() << endl
367 << " File: " << D.FileList().File().FileName() << endl
368 << " MD5: " << D.md5() << endl;
369 }
1164783d
AL
370 }
371 }
372
b2e465d6 373 for (pkgCache::PkgFileIterator F = Cache.FileBegin(); F.end() == false; F++)
1164783d
AL
374 {
375 cout << "File: " << F.FileName() << endl;
b2e465d6 376 cout << " Type: " << F.IndexType() << endl;
1164783d
AL
377 cout << " Size: " << F->Size << endl;
378 cout << " ID: " << F->ID << endl;
379 cout << " Flags: " << F->Flags << endl;
b0b4efb9 380 cout << " Time: " << TimeRFC1123(F->mtime) << endl;
076d01b0
AL
381 cout << " Archive: " << DeNull(F.Archive()) << endl;
382 cout << " Component: " << DeNull(F.Component()) << endl;
383 cout << " Version: " << DeNull(F.Version()) << endl;
384 cout << " Origin: " << DeNull(F.Origin()) << endl;
385 cout << " Site: " << DeNull(F.Site()) << endl;
386 cout << " Label: " << DeNull(F.Label()) << endl;
387 cout << " Architecture: " << DeNull(F.Architecture()) << endl;
1164783d
AL
388 }
389
390 return true;
391}
392 /*}}}*/
393// DumpAvail - Print out the available list /*{{{*/
394// ---------------------------------------------------------------------
b2e465d6
AL
395/* This is needed to make dpkg --merge happy.. I spent a bit of time to
396 make this run really fast, perhaps I went a little overboard.. */
b0b4efb9 397bool DumpAvail(CommandLine &Cmd)
1164783d 398{
b0b4efb9 399 pkgCache &Cache = *GCache;
1164783d 400
b2e465d6 401 pkgPolicy Plcy(&Cache);
e68ca100 402 if (ReadPinFile(Plcy) == false || ReadPinDir(Plcy) == false)
b2e465d6
AL
403 return false;
404
fe648919
AL
405 unsigned long Count = Cache.HeaderP->PackageCount+1;
406 pkgCache::VerFile **VFList = new pkgCache::VerFile *[Count];
407 memset(VFList,0,sizeof(*VFList)*Count);
b2e465d6
AL
408
409 // Map versions that we want to write out onto the VerList array.
410 for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
411 {
412 if (P->VersionList == 0)
5b8c90bf
AL
413 continue;
414
b2e465d6
AL
415 /* Find the proper version to use. If the policy says there are no
416 possible selections we return the installed version, if available..
417 This prevents dselect from making it obsolete. */
418 pkgCache::VerIterator V = Plcy.GetCandidateVer(P);
419 if (V.end() == true)
ad00ae81 420 {
b2e465d6
AL
421 if (P->CurrentVer == 0)
422 continue;
423 V = P.CurrentVer();
ad00ae81 424 }
1164783d 425
b2e465d6
AL
426 pkgCache::VerFileIterator VF = V.FileList();
427 for (; VF.end() == false ; VF++)
428 if ((VF.File()->Flags & pkgCache::Flag::NotSource) == 0)
429 break;
430
431 /* Okay, here we have a bit of a problem.. The policy has selected the
432 currently installed package - however it only exists in the
433 status file.. We need to write out something or dselect will mark
434 the package as obsolete! Thus we emit the status file entry, but
435 below we remove the status line to make it valid for the
436 available file. However! We only do this if their do exist *any*
437 non-source versions of the package - that way the dselect obsolete
438 handling works OK. */
439 if (VF.end() == true)
1164783d 440 {
b2e465d6
AL
441 for (pkgCache::VerIterator Cur = P.VersionList(); Cur.end() != true; Cur++)
442 {
443 for (VF = Cur.FileList(); VF.end() == false; VF++)
444 {
445 if ((VF.File()->Flags & pkgCache::Flag::NotSource) == 0)
446 {
447 VF = V.FileList();
448 break;
449 }
450 }
451
452 if (VF.end() == false)
453 break;
454 }
ad00ae81 455 }
b2e465d6
AL
456
457 VFList[P->ID] = VF;
458 }
459
fe648919 460 LocalitySort(VFList,Count,sizeof(*VFList));
ad00ae81 461
b2e465d6
AL
462 // Iterate over all the package files and write them out.
463 char *Buffer = new char[Cache.HeaderP->MaxVerFileSize+10];
464 for (pkgCache::VerFile **J = VFList; *J != 0;)
465 {
466 pkgCache::PkgFileIterator File(Cache,(*J)->File + Cache.PkgFileP);
467 if (File.IsOk() == false)
ad00ae81 468 {
b2e465d6
AL
469 _error->Error(_("Package file %s is out of sync."),File.FileName());
470 break;
471 }
bd432be3 472
b2e465d6
AL
473 FileFd PkgF(File.FileName(),FileFd::ReadOnly);
474 if (_error->PendingError() == true)
475 break;
476
477 /* Write all of the records from this package file, since we
478 already did locality sorting we can now just seek through the
479 file in read order. We apply 1 more optimization here, since often
480 there will be < 1 byte gaps between records (for the \n) we read that
481 into the next buffer and offset a bit.. */
482 unsigned long Pos = 0;
483 for (; *J != 0; J++)
484 {
485 if ((*J)->File + Cache.PkgFileP != File)
486 break;
bd432be3 487
b2e465d6
AL
488 const pkgCache::VerFile &VF = **J;
489
bd432be3 490 // Read the record and then write it out again.
b2e465d6
AL
491 unsigned long Jitter = VF.Offset - Pos;
492 if (Jitter > 8)
1164783d 493 {
b2e465d6
AL
494 if (PkgF.Seek(VF.Offset) == false)
495 break;
496 Jitter = 0;
497 }
498
499 if (PkgF.Read(Buffer,VF.Size + Jitter) == false)
500 break;
501 Buffer[VF.Size + Jitter] = '\n';
502
503 // See above..
504 if ((File->Flags & pkgCache::Flag::NotSource) == pkgCache::Flag::NotSource)
505 {
506 pkgTagSection Tags;
e8cbb49f 507 TFRewriteData RW[] = {{"Status",0},{"Config-Version",0},{}};
b2e465d6
AL
508 const char *Zero = 0;
509 if (Tags.Scan(Buffer+Jitter,VF.Size+1) == false ||
510 TFRewrite(stdout,Tags,&Zero,RW) == false)
511 {
512 _error->Error("Internal Error, Unable to parse a package record");
513 break;
514 }
515 fputc('\n',stdout);
516 }
517 else
518 {
519 if (fwrite(Buffer+Jitter,VF.Size+1,1,stdout) != 1)
520 break;
521 }
522
523 Pos = VF.Offset + VF.Size;
1164783d 524 }
b2e465d6
AL
525
526 fflush(stdout);
527 if (_error->PendingError() == true)
528 break;
ad00ae81
AL
529 }
530
b2e465d6
AL
531 delete [] Buffer;
532 delete [] VFList;
533 return !_error->PendingError();
349cd3b8
AL
534}
535 /*}}}*/
4b1b89c5 536// Depends - Print out a dependency tree /*{{{*/
349cd3b8
AL
537// ---------------------------------------------------------------------
538/* */
539bool Depends(CommandLine &CmdL)
540{
541 pkgCache &Cache = *GCache;
b2e465d6
AL
542 SPtrArray<unsigned> Colours = new unsigned[Cache.Head().PackageCount];
543 memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount);
349cd3b8
AL
544
545 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
546 {
547 pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
548 if (Pkg.end() == true)
549 {
b2e465d6 550 _error->Warning(_("Unable to locate package %s"),*I);
349cd3b8
AL
551 continue;
552 }
b2e465d6
AL
553 Colours[Pkg->ID] = 1;
554 }
555
556 bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false);
eba2b51d 557 bool Installed = _config->FindB("APT::Cache::Installed",false);
5aa95c86 558 bool Important = _config->FindB("APT::Cache::Important",false);
b2e465d6
AL
559 bool DidSomething;
560 do
561 {
562 DidSomething = false;
563 for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
349cd3b8 564 {
b2e465d6
AL
565 if (Colours[Pkg->ID] != 1)
566 continue;
567 Colours[Pkg->ID] = 2;
568 DidSomething = true;
349cd3b8 569
b2e465d6
AL
570 pkgCache::VerIterator Ver = Pkg.VersionList();
571 if (Ver.end() == true)
349cd3b8 572 {
b2e465d6
AL
573 cout << '<' << Pkg.Name() << '>' << endl;
574 continue;
349cd3b8 575 }
b2e465d6
AL
576
577 cout << Pkg.Name() << endl;
578
579 for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
580 {
5aa95c86
MV
581 // Important deps only
582 if (Important == true)
583 if (D->Type != pkgCache::Dep::PreDepends &&
584 D->Type != pkgCache::Dep::Depends)
585 continue;
586
b2e465d6 587 pkgCache::PkgIterator Trg = D.TargetPkg();
eba2b51d
AL
588
589 if((Installed && Trg->CurrentVer != 0) || !Installed)
590 {
591
592 if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
593 cout << " |";
594 else
595 cout << " ";
b2e465d6 596
eba2b51d
AL
597 // Show the package
598 if (Trg->VersionList == 0)
599 cout << D.DepType() << ": <" << Trg.Name() << ">" << endl;
600 else
601 cout << D.DepType() << ": " << Trg.Name() << endl;
602
603 if (Recurse == true)
604 Colours[D.TargetPkg()->ID]++;
605
606 }
b2e465d6
AL
607
608 // Display all solutions
609 SPtrArray<pkgCache::Version *> List = D.AllTargets();
610 pkgPrioSortList(Cache,List);
611 for (pkgCache::Version **I = List; *I != 0; I++)
612 {
613 pkgCache::VerIterator V(Cache,*I);
614 if (V != Cache.VerP + V.ParentPkg()->VersionList ||
615 V->ParentPkg == D->Package)
616 continue;
617 cout << " " << V.ParentPkg().Name() << endl;
618
619 if (Recurse == true)
620 Colours[D.ParentPkg()->ID]++;
621 }
622 }
623 }
349cd3b8 624 }
b2e465d6 625 while (DidSomething == true);
349cd3b8 626
3e94da1b
AL
627 return true;
628}
92fcbfc1 629 /*}}}*/
eba2b51d
AL
630// RDepends - Print out a reverse dependency tree - mbc /*{{{*/
631// ---------------------------------------------------------------------
632/* */
633bool RDepends(CommandLine &CmdL)
634{
635 pkgCache &Cache = *GCache;
636 SPtrArray<unsigned> Colours = new unsigned[Cache.Head().PackageCount];
637 memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount);
638
639 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
640 {
641 pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
642 if (Pkg.end() == true)
643 {
644 _error->Warning(_("Unable to locate package %s"),*I);
645 continue;
646 }
647 Colours[Pkg->ID] = 1;
648 }
649
650 bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false);
651 bool Installed = _config->FindB("APT::Cache::Installed",false);
652 bool DidSomething;
653 do
654 {
655 DidSomething = false;
656 for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
657 {
658 if (Colours[Pkg->ID] != 1)
659 continue;
660 Colours[Pkg->ID] = 2;
661 DidSomething = true;
662
663 pkgCache::VerIterator Ver = Pkg.VersionList();
664 if (Ver.end() == true)
665 {
666 cout << '<' << Pkg.Name() << '>' << endl;
667 continue;
668 }
669
670 cout << Pkg.Name() << endl;
671
672 cout << "Reverse Depends:" << endl;
673 for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false; D++)
674 {
675 // Show the package
676 pkgCache::PkgIterator Trg = D.ParentPkg();
677
678 if((Installed && Trg->CurrentVer != 0) || !Installed)
679 {
680
681 if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
682 cout << " |";
683 else
684 cout << " ";
685
686 if (Trg->VersionList == 0)
687 cout << D.DepType() << ": <" << Trg.Name() << ">" << endl;
688 else
689 cout << Trg.Name() << endl;
690
691 if (Recurse == true)
692 Colours[D.ParentPkg()->ID]++;
693
694 }
695
696 // Display all solutions
697 SPtrArray<pkgCache::Version *> List = D.AllTargets();
698 pkgPrioSortList(Cache,List);
699 for (pkgCache::Version **I = List; *I != 0; I++)
700 {
701 pkgCache::VerIterator V(Cache,*I);
702 if (V != Cache.VerP + V.ParentPkg()->VersionList ||
703 V->ParentPkg == D->Package)
704 continue;
705 cout << " " << V.ParentPkg().Name() << endl;
706
707 if (Recurse == true)
708 Colours[D.ParentPkg()->ID]++;
709 }
710 }
711 }
712 }
713 while (DidSomething == true);
714
715 return true;
716}
3e94da1b 717 /*}}}*/
fff4b7f3
AL
718// xvcg - Generate a graph for xvcg /*{{{*/
719// ---------------------------------------------------------------------
720// Code contributed from Junichi Uekawa <dancer@debian.org> on 20 June 2002.
721
722bool XVcg(CommandLine &CmdL)
723{
724 pkgCache &Cache = *GCache;
725 bool GivenOnly = _config->FindB("APT::Cache::GivenOnly",false);
726
727 /* Normal packages are boxes
728 Pure Provides are triangles
729 Mixed are diamonds
730 rhomb are missing packages*/
731 const char *Shapes[] = {"ellipse","triangle","box","rhomb"};
732
733 /* Initialize the list of packages to show.
734 1 = To Show
735 2 = To Show no recurse
736 3 = Emitted no recurse
737 4 = Emitted
738 0 = None */
739 enum States {None=0, ToShow, ToShowNR, DoneNR, Done};
740 enum TheFlags {ForceNR=(1<<0)};
741 unsigned char *Show = new unsigned char[Cache.Head().PackageCount];
742 unsigned char *Flags = new unsigned char[Cache.Head().PackageCount];
743 unsigned char *ShapeMap = new unsigned char[Cache.Head().PackageCount];
744
745 // Show everything if no arguments given
746 if (CmdL.FileList[1] == 0)
747 for (unsigned long I = 0; I != Cache.Head().PackageCount; I++)
748 Show[I] = ToShow;
749 else
750 for (unsigned long I = 0; I != Cache.Head().PackageCount; I++)
751 Show[I] = None;
752 memset(Flags,0,sizeof(*Flags)*Cache.Head().PackageCount);
753
754 // Map the shapes
755 for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
756 {
757 if (Pkg->VersionList == 0)
758 {
759 // Missing
760 if (Pkg->ProvidesList == 0)
761 ShapeMap[Pkg->ID] = 0;
762 else
763 ShapeMap[Pkg->ID] = 1;
764 }
765 else
766 {
767 // Normal
768 if (Pkg->ProvidesList == 0)
769 ShapeMap[Pkg->ID] = 2;
770 else
771 ShapeMap[Pkg->ID] = 3;
772 }
773 }
774
775 // Load the list of packages from the command line into the show list
776 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
777 {
778 // Process per-package flags
779 string P = *I;
780 bool Force = false;
781 if (P.length() > 3)
782 {
783 if (P.end()[-1] == '^')
784 {
785 Force = true;
786 P.erase(P.end()-1);
787 }
788
789 if (P.end()[-1] == ',')
790 P.erase(P.end()-1);
791 }
792
793 // Locate the package
794 pkgCache::PkgIterator Pkg = Cache.FindPkg(P);
795 if (Pkg.end() == true)
796 {
797 _error->Warning(_("Unable to locate package %s"),*I);
798 continue;
799 }
800 Show[Pkg->ID] = ToShow;
801
802 if (Force == true)
803 Flags[Pkg->ID] |= ForceNR;
804 }
805
806 // Little header
807 cout << "graph: { title: \"packages\"" << endl <<
808 "xmax: 700 ymax: 700 x: 30 y: 30" << endl <<
809 "layout_downfactor: 8" << endl;
810
811 bool Act = true;
812 while (Act == true)
813 {
814 Act = false;
815 for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
816 {
817 // See we need to show this package
818 if (Show[Pkg->ID] == None || Show[Pkg->ID] >= DoneNR)
819 continue;
820
821 //printf ("node: { title: \"%s\" label: \"%s\" }\n", Pkg.Name(), Pkg.Name());
822
823 // Colour as done
824 if (Show[Pkg->ID] == ToShowNR || (Flags[Pkg->ID] & ForceNR) == ForceNR)
825 {
826 // Pure Provides and missing packages have no deps!
827 if (ShapeMap[Pkg->ID] == 0 || ShapeMap[Pkg->ID] == 1)
828 Show[Pkg->ID] = Done;
829 else
830 Show[Pkg->ID] = DoneNR;
831 }
832 else
833 Show[Pkg->ID] = Done;
834 Act = true;
835
836 // No deps to map out
837 if (Pkg->VersionList == 0 || Show[Pkg->ID] == DoneNR)
838 continue;
839
840 pkgCache::VerIterator Ver = Pkg.VersionList();
841 for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
842 {
843 // See if anything can meet this dep
844 // Walk along the actual package providing versions
845 bool Hit = false;
846 pkgCache::PkgIterator DPkg = D.TargetPkg();
847 for (pkgCache::VerIterator I = DPkg.VersionList();
848 I.end() == false && Hit == false; I++)
849 {
850 if (Cache.VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true)
851 Hit = true;
852 }
853
854 // Follow all provides
855 for (pkgCache::PrvIterator I = DPkg.ProvidesList();
856 I.end() == false && Hit == false; I++)
857 {
858 if (Cache.VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false)
859 Hit = true;
860 }
861
862
863 // Only graph critical deps
864 if (D.IsCritical() == true)
865 {
866 printf ("edge: { sourcename: \"%s\" targetname: \"%s\" class: 2 ",Pkg.Name(), D.TargetPkg().Name() );
867
868 // Colour the node for recursion
869 if (Show[D.TargetPkg()->ID] <= DoneNR)
870 {
871 /* If a conflicts does not meet anything in the database
872 then show the relation but do not recurse */
873 if (Hit == false &&
874 (D->Type == pkgCache::Dep::Conflicts ||
308c7d30 875 D->Type == pkgCache::Dep::DpkgBreaks ||
fff4b7f3
AL
876 D->Type == pkgCache::Dep::Obsoletes))
877 {
878 if (Show[D.TargetPkg()->ID] == None &&
879 Show[D.TargetPkg()->ID] != ToShow)
880 Show[D.TargetPkg()->ID] = ToShowNR;
881 }
882 else
883 {
884 if (GivenOnly == true && Show[D.TargetPkg()->ID] != ToShow)
885 Show[D.TargetPkg()->ID] = ToShowNR;
886 else
887 Show[D.TargetPkg()->ID] = ToShow;
888 }
889 }
890
891 // Edge colour
892 switch(D->Type)
893 {
894 case pkgCache::Dep::Conflicts:
895 printf("label: \"conflicts\" color: lightgreen }\n");
896 break;
308c7d30
IJ
897 case pkgCache::Dep::DpkgBreaks:
898 printf("label: \"breaks\" color: lightgreen }\n");
899 break;
fff4b7f3
AL
900 case pkgCache::Dep::Obsoletes:
901 printf("label: \"obsoletes\" color: lightgreen }\n");
902 break;
903
904 case pkgCache::Dep::PreDepends:
905 printf("label: \"predepends\" color: blue }\n");
906 break;
907
908 default:
909 printf("}\n");
910 break;
911 }
912 }
913 }
914 }
915 }
916
917 /* Draw the box colours after the fact since we can not tell what colour
918 they should be until everything is finished drawing */
919 for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
920 {
921 if (Show[Pkg->ID] < DoneNR)
922 continue;
923
924 if (Show[Pkg->ID] == DoneNR)
925 printf("node: { title: \"%s\" label: \"%s\" color: orange shape: %s }\n", Pkg.Name(), Pkg.Name(),
926 Shapes[ShapeMap[Pkg->ID]]);
927 else
928 printf("node: { title: \"%s\" label: \"%s\" shape: %s }\n", Pkg.Name(), Pkg.Name(),
929 Shapes[ShapeMap[Pkg->ID]]);
930
931 }
932
933 printf("}\n");
934 return true;
935}
936 /*}}}*/
3e94da1b
AL
937// Dotty - Generate a graph for Dotty /*{{{*/
938// ---------------------------------------------------------------------
939/* Dotty is the graphvis program for generating graphs. It is a fairly
940 simple queuing algorithm that just writes dependencies and nodes.
941 http://www.research.att.com/sw/tools/graphviz/ */
942bool Dotty(CommandLine &CmdL)
943{
944 pkgCache &Cache = *GCache;
945 bool GivenOnly = _config->FindB("APT::Cache::GivenOnly",false);
946
947 /* Normal packages are boxes
948 Pure Provides are triangles
949 Mixed are diamonds
950 Hexagons are missing packages*/
951 const char *Shapes[] = {"hexagon","triangle","box","diamond"};
952
953 /* Initialize the list of packages to show.
954 1 = To Show
955 2 = To Show no recurse
956 3 = Emitted no recurse
957 4 = Emitted
958 0 = None */
959 enum States {None=0, ToShow, ToShowNR, DoneNR, Done};
960 enum TheFlags {ForceNR=(1<<0)};
961 unsigned char *Show = new unsigned char[Cache.Head().PackageCount];
962 unsigned char *Flags = new unsigned char[Cache.Head().PackageCount];
963 unsigned char *ShapeMap = new unsigned char[Cache.Head().PackageCount];
964
965 // Show everything if no arguments given
966 if (CmdL.FileList[1] == 0)
967 for (unsigned long I = 0; I != Cache.Head().PackageCount; I++)
968 Show[I] = ToShow;
969 else
970 for (unsigned long I = 0; I != Cache.Head().PackageCount; I++)
971 Show[I] = None;
972 memset(Flags,0,sizeof(*Flags)*Cache.Head().PackageCount);
973
974 // Map the shapes
975 for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
976 {
977 if (Pkg->VersionList == 0)
978 {
979 // Missing
980 if (Pkg->ProvidesList == 0)
981 ShapeMap[Pkg->ID] = 0;
982 else
983 ShapeMap[Pkg->ID] = 1;
984 }
985 else
986 {
987 // Normal
988 if (Pkg->ProvidesList == 0)
989 ShapeMap[Pkg->ID] = 2;
990 else
991 ShapeMap[Pkg->ID] = 3;
992 }
993 }
994
995 // Load the list of packages from the command line into the show list
996 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
997 {
998 // Process per-package flags
999 string P = *I;
1000 bool Force = false;
1001 if (P.length() > 3)
1002 {
1003 if (P.end()[-1] == '^')
1004 {
1005 Force = true;
1006 P.erase(P.end()-1);
1007 }
1008
1009 if (P.end()[-1] == ',')
1010 P.erase(P.end()-1);
1011 }
1012
1013 // Locate the package
1014 pkgCache::PkgIterator Pkg = Cache.FindPkg(P);
1015 if (Pkg.end() == true)
1016 {
b2e465d6 1017 _error->Warning(_("Unable to locate package %s"),*I);
3e94da1b
AL
1018 continue;
1019 }
1020 Show[Pkg->ID] = ToShow;
1021
1022 if (Force == true)
1023 Flags[Pkg->ID] |= ForceNR;
1024 }
1025
1026 // Little header
1027 printf("digraph packages {\n");
1028 printf("concentrate=true;\n");
1029 printf("size=\"30,40\";\n");
1030
1031 bool Act = true;
1032 while (Act == true)
1033 {
1034 Act = false;
1035 for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
1036 {
1037 // See we need to show this package
1038 if (Show[Pkg->ID] == None || Show[Pkg->ID] >= DoneNR)
1039 continue;
1040
1041 // Colour as done
1042 if (Show[Pkg->ID] == ToShowNR || (Flags[Pkg->ID] & ForceNR) == ForceNR)
1043 {
1044 // Pure Provides and missing packages have no deps!
1045 if (ShapeMap[Pkg->ID] == 0 || ShapeMap[Pkg->ID] == 1)
1046 Show[Pkg->ID] = Done;
1047 else
1048 Show[Pkg->ID] = DoneNR;
1049 }
1050 else
1051 Show[Pkg->ID] = Done;
1052 Act = true;
1053
1054 // No deps to map out
1055 if (Pkg->VersionList == 0 || Show[Pkg->ID] == DoneNR)
1056 continue;
1057
1058 pkgCache::VerIterator Ver = Pkg.VersionList();
1059 for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
1060 {
1061 // See if anything can meet this dep
1062 // Walk along the actual package providing versions
1063 bool Hit = false;
1064 pkgCache::PkgIterator DPkg = D.TargetPkg();
1065 for (pkgCache::VerIterator I = DPkg.VersionList();
1066 I.end() == false && Hit == false; I++)
1067 {
b2e465d6 1068 if (Cache.VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true)
3e94da1b
AL
1069 Hit = true;
1070 }
1071
1072 // Follow all provides
1073 for (pkgCache::PrvIterator I = DPkg.ProvidesList();
1074 I.end() == false && Hit == false; I++)
1075 {
b2e465d6 1076 if (Cache.VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false)
3e94da1b
AL
1077 Hit = true;
1078 }
1079
1080 // Only graph critical deps
1081 if (D.IsCritical() == true)
1082 {
1083 printf("\"%s\" -> \"%s\"",Pkg.Name(),D.TargetPkg().Name());
1084
1085 // Colour the node for recursion
1086 if (Show[D.TargetPkg()->ID] <= DoneNR)
1087 {
1088 /* If a conflicts does not meet anything in the database
1089 then show the relation but do not recurse */
b2e465d6
AL
1090 if (Hit == false &&
1091 (D->Type == pkgCache::Dep::Conflicts ||
1092 D->Type == pkgCache::Dep::Obsoletes))
3e94da1b
AL
1093 {
1094 if (Show[D.TargetPkg()->ID] == None &&
1095 Show[D.TargetPkg()->ID] != ToShow)
1096 Show[D.TargetPkg()->ID] = ToShowNR;
1097 }
1098 else
1099 {
1100 if (GivenOnly == true && Show[D.TargetPkg()->ID] != ToShow)
1101 Show[D.TargetPkg()->ID] = ToShowNR;
1102 else
1103 Show[D.TargetPkg()->ID] = ToShow;
1104 }
1105 }
1106
1107 // Edge colour
1108 switch(D->Type)
1109 {
1110 case pkgCache::Dep::Conflicts:
b2e465d6 1111 case pkgCache::Dep::Obsoletes:
3e94da1b
AL
1112 printf("[color=springgreen];\n");
1113 break;
1114
1115 case pkgCache::Dep::PreDepends:
1116 printf("[color=blue];\n");
1117 break;
1118
1119 default:
1120 printf(";\n");
1121 break;
1122 }
1123 }
1124 }
1125 }
1126 }
1127
1128 /* Draw the box colours after the fact since we can not tell what colour
1129 they should be until everything is finished drawing */
1130 for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
1131 {
1132 if (Show[Pkg->ID] < DoneNR)
1133 continue;
1134
1135 // Orange box for early recursion stoppage
1136 if (Show[Pkg->ID] == DoneNR)
1137 printf("\"%s\" [color=orange,shape=%s];\n",Pkg.Name(),
1138 Shapes[ShapeMap[Pkg->ID]]);
1139 else
1140 printf("\"%s\" [shape=%s];\n",Pkg.Name(),
1141 Shapes[ShapeMap[Pkg->ID]]);
1142 }
1143
1144 printf("}\n");
ad00ae81
AL
1145 return true;
1146}
1147 /*}}}*/
1148// DoAdd - Perform an adding operation /*{{{*/
1149// ---------------------------------------------------------------------
1150/* */
e1b74f61 1151bool DoAdd(CommandLine &CmdL)
ad00ae81 1152{
b2e465d6
AL
1153 return _error->Error("Unimplemented");
1154#if 0
e1b74f61
AL
1155 // Make sure there is at least one argument
1156 if (CmdL.FileSize() <= 1)
1157 return _error->Error("You must give at least one file name");
ad00ae81
AL
1158
1159 // Open the cache
018f1533 1160 FileFd CacheF(_config->FindFile("Dir::Cache::pkgcache"),FileFd::WriteAny);
ad00ae81
AL
1161 if (_error->PendingError() == true)
1162 return false;
1163
1164 DynamicMMap Map(CacheF,MMap::Public);
1165 if (_error->PendingError() == true)
1166 return false;
404ec98e 1167
0a8e3465 1168 OpTextProgress Progress(*_config);
404ec98e 1169 pkgCacheGenerator Gen(Map,Progress);
ad00ae81
AL
1170 if (_error->PendingError() == true)
1171 return false;
1172
e1b74f61
AL
1173 unsigned long Length = CmdL.FileSize() - 1;
1174 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
ad00ae81 1175 {
e1b74f61 1176 Progress.OverallProgress(I - CmdL.FileList,Length,1,"Generating cache");
018f1533
AL
1177 Progress.SubProgress(Length);
1178
ad00ae81 1179 // Do the merge
e1b74f61 1180 FileFd TagF(*I,FileFd::ReadOnly);
ad00ae81
AL
1181 debListParser Parser(TagF);
1182 if (_error->PendingError() == true)
e1b74f61 1183 return _error->Error("Problem opening %s",*I);
ad00ae81 1184
b2e465d6 1185 if (Gen.SelectFile(*I,"") == false)
ad00ae81
AL
1186 return _error->Error("Problem with SelectFile");
1187
1188 if (Gen.MergeList(Parser) == false)
1189 return _error->Error("Problem with MergeList");
1164783d 1190 }
404ec98e
AL
1191
1192 Progress.Done();
b0b4efb9
AL
1193 GCache = &Gen.GetCache();
1194 Stats(CmdL);
ad00ae81 1195
7e2e2d5d 1196 return true;
b2e465d6 1197#endif
7e2e2d5d
AL
1198}
1199 /*}}}*/
1200// DisplayRecord - Displays the complete record for the package /*{{{*/
1201// ---------------------------------------------------------------------
1202/* This displays the package record from the proper package index file.
1203 It is not used by DumpAvail for performance reasons. */
1204bool DisplayRecord(pkgCache::VerIterator V)
1205{
1206 // Find an appropriate file
1207 pkgCache::VerFileIterator Vf = V.FileList();
1208 for (; Vf.end() == false; Vf++)
1209 if ((Vf.File()->Flags & pkgCache::Flag::NotSource) == 0)
1210 break;
1211 if (Vf.end() == true)
1212 Vf = V.FileList();
1213
1214 // Check and load the package list file
1215 pkgCache::PkgFileIterator I = Vf.File();
1216 if (I.IsOk() == false)
b2e465d6 1217 return _error->Error(_("Package file %s is out of sync."),I.FileName());
7e2e2d5d
AL
1218
1219 FileFd PkgF(I.FileName(),FileFd::ReadOnly);
1220 if (_error->PendingError() == true)
1221 return false;
1222
a52f938b 1223 // Read the record
b2e465d6
AL
1224 unsigned char *Buffer = new unsigned char[GCache->HeaderP->MaxVerFileSize+1];
1225 Buffer[V.FileList()->Size] = '\n';
7e2e2d5d 1226 if (PkgF.Seek(V.FileList()->Offset) == false ||
a52f938b 1227 PkgF.Read(Buffer,V.FileList()->Size) == false)
7e2e2d5d
AL
1228 {
1229 delete [] Buffer;
1230 return false;
1231 }
a52f938b 1232
e5e2d176 1233 // Get a pointer to start of Description field
e011829d 1234 const unsigned char *DescP = (unsigned char*)strstr((char*)Buffer, "Description:");
e5e2d176
MV
1235
1236 // Write all but Description
487d7faa 1237 if (fwrite(Buffer,1,DescP - Buffer,stdout) < (size_t)(DescP - Buffer))
a52f938b
OS
1238 {
1239 delete [] Buffer;
1240 return false;
1241 }
1242
a52f938b
OS
1243 // Show the right description
1244 pkgRecords Recs(*GCache);
012b102a 1245 pkgCache::DescIterator Desc = V.TranslatedDescription();
a52f938b 1246 pkgRecords::Parser &P = Recs.Lookup(Desc.FileList());
e011829d 1247 cout << "Description" << ( (strcmp(Desc.LanguageCode(),"") != 0) ? "-" : "" ) << Desc.LanguageCode() << ": " << P.LongDesc();
a52f938b 1248
e011829d
MV
1249 // Find the first field after the description (if there is any)
1250 for(DescP++;DescP != &Buffer[V.FileList()->Size];DescP++)
1251 {
1252 if(*DescP == '\n' && *(DescP+1) != ' ')
1253 {
1254 // write the rest of the buffer
1255 const unsigned char *end=&Buffer[V.FileList()->Size];
1256 if (fwrite(DescP,1,end-DescP,stdout) < (size_t)(end-DescP))
1257 {
1258 delete [] Buffer;
1259 return false;
1260 }
1261
1262 break;
1263 }
1264 }
1265 // write a final newline (after the description)
1266 cout<<endl;
7e2e2d5d
AL
1267 delete [] Buffer;
1268
9dbb421f
AL
1269 return true;
1270}
1271 /*}}}*/
1272// Search - Perform a search /*{{{*/
1273// ---------------------------------------------------------------------
9b5d79ec 1274/* This searches the package names and package descriptions for a pattern */
a52f938b 1275struct ExDescFile
b2e465d6 1276{
a52f938b 1277 pkgCache::DescFile *Df;
b2e465d6
AL
1278 bool NameMatch;
1279};
1280
92fcbfc1
DK
1281// Search - Perform a search /*{{{*/
1282// ---------------------------------------------------------------------
1283/* This searches the package names and package descriptions for a pattern */
9dbb421f
AL
1284bool Search(CommandLine &CmdL)
1285{
1286 pkgCache &Cache = *GCache;
7e2e2d5d
AL
1287 bool ShowFull = _config->FindB("APT::Cache::ShowFull",false);
1288 bool NamesOnly = _config->FindB("APT::Cache::NamesOnly",false);
b2e465d6
AL
1289 unsigned NumPatterns = CmdL.FileSize() -1;
1290
1291 pkgDepCache::Policy Plcy;
9dbb421f
AL
1292
1293 // Make sure there is at least one argument
b2e465d6
AL
1294 if (NumPatterns < 1)
1295 return _error->Error(_("You must give exactly one pattern"));
9dbb421f
AL
1296
1297 // Compile the regex pattern
b2e465d6
AL
1298 regex_t *Patterns = new regex_t[NumPatterns];
1299 memset(Patterns,0,sizeof(*Patterns)*NumPatterns);
1300 for (unsigned I = 0; I != NumPatterns; I++)
1301 {
1302 if (regcomp(&Patterns[I],CmdL.FileList[I+1],REG_EXTENDED | REG_ICASE |
1303 REG_NOSUB) != 0)
1304 {
1305 for (; I != 0; I--)
1306 regfree(&Patterns[I]);
1307 return _error->Error("Regex compilation error");
1308 }
1309 }
9dbb421f
AL
1310
1311 // Create the text record parser
1312 pkgRecords Recs(Cache);
1313 if (_error->PendingError() == true)
b2e465d6
AL
1314 {
1315 for (unsigned I = 0; I != NumPatterns; I++)
1316 regfree(&Patterns[I]);
9dbb421f 1317 return false;
b2e465d6 1318 }
9dbb421f 1319
a52f938b
OS
1320 ExDescFile *DFList = new ExDescFile[Cache.HeaderP->PackageCount+1];
1321 memset(DFList,0,sizeof(*DFList)*Cache.HeaderP->PackageCount+1);
b2e465d6
AL
1322
1323 // Map versions that we want to write out onto the VerList array.
1324 for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
9dbb421f 1325 {
a52f938b 1326 DFList[P->ID].NameMatch = NumPatterns != 0;
b2e465d6
AL
1327 for (unsigned I = 0; I != NumPatterns; I++)
1328 {
1329 if (regexec(&Patterns[I],P.Name(),0,0,0) == 0)
a52f938b 1330 DFList[P->ID].NameMatch &= true;
0f2fa322 1331 else
a52f938b 1332 DFList[P->ID].NameMatch = false;
b2e465d6 1333 }
c29652b0 1334
b2e465d6 1335 // Doing names only, drop any that dont match..
a52f938b 1336 if (NamesOnly == true && DFList[P->ID].NameMatch == false)
b2e465d6
AL
1337 continue;
1338
1339 // Find the proper version to use.
1340 pkgCache::VerIterator V = Plcy.GetCandidateVer(P);
c29652b0 1341 if (V.end() == false)
a52f938b 1342 DFList[P->ID].Df = V.DescriptionList().FileList();
c29652b0
AL
1343 }
1344
1345 // Include all the packages that provide matching names too
1346 for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
1347 {
a52f938b 1348 if (DFList[P->ID].NameMatch == false)
7e2e2d5d 1349 continue;
c29652b0
AL
1350
1351 for (pkgCache::PrvIterator Prv = P.ProvidesList() ; Prv.end() == false; Prv++)
1352 {
1353 pkgCache::VerIterator V = Plcy.GetCandidateVer(Prv.OwnerPkg());
1354 if (V.end() == false)
1355 {
a52f938b
OS
1356 DFList[Prv.OwnerPkg()->ID].Df = V.DescriptionList().FileList();
1357 DFList[Prv.OwnerPkg()->ID].NameMatch = true;
c29652b0
AL
1358 }
1359 }
b2e465d6 1360 }
a52f938b
OS
1361
1362 LocalitySort(&DFList->Df,Cache.HeaderP->PackageCount,sizeof(*DFList));
7e2e2d5d 1363
b2e465d6 1364 // Iterate over all the version records and check them
a52f938b 1365 for (ExDescFile *J = DFList; J->Df != 0; J++)
b2e465d6 1366 {
a52f938b 1367 pkgRecords::Parser &P = Recs.Lookup(pkgCache::DescFileIterator(Cache,J->Df));
0f2fa322
AL
1368
1369 bool Match = true;
1370 if (J->NameMatch == false)
1371 {
1372 string LongDesc = P.LongDesc();
1373 Match = NumPatterns != 0;
1374 for (unsigned I = 0; I != NumPatterns; I++)
1375 {
1376 if (regexec(&Patterns[I],LongDesc.c_str(),0,0,0) == 0)
1377 Match &= true;
1378 else
1379 Match = false;
1380 }
1381 }
b2e465d6
AL
1382
1383 if (Match == true)
9dbb421f 1384 {
7e2e2d5d 1385 if (ShowFull == true)
b2e465d6
AL
1386 {
1387 const char *Start;
1388 const char *End;
1389 P.GetRec(Start,End);
1390 fwrite(Start,End-Start,1,stdout);
1391 putc('\n',stdout);
1392 }
7e2e2d5d 1393 else
b2e465d6
AL
1394 printf("%s - %s\n",P.Name().c_str(),P.ShortDesc().c_str());
1395 }
9dbb421f
AL
1396 }
1397
a52f938b 1398 delete [] DFList;
b2e465d6
AL
1399 for (unsigned I = 0; I != NumPatterns; I++)
1400 regfree(&Patterns[I]);
1401 if (ferror(stdout))
1402 return _error->Error("Write to stdout failed");
1164783d
AL
1403 return true;
1404}
1405 /*}}}*/
7e2e2d5d
AL
1406// ShowPackage - Dump the package record to the screen /*{{{*/
1407// ---------------------------------------------------------------------
1408/* */
1409bool ShowPackage(CommandLine &CmdL)
1410{
1411 pkgCache &Cache = *GCache;
b2e465d6 1412 pkgDepCache::Policy Plcy;
9d366c89
AL
1413
1414 unsigned found = 0;
b2e465d6 1415
7e2e2d5d
AL
1416 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
1417 {
1418 pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
1419 if (Pkg.end() == true)
1420 {
b2e465d6 1421 _error->Warning(_("Unable to locate package %s"),*I);
7e2e2d5d
AL
1422 continue;
1423 }
b2e465d6 1424
9d366c89
AL
1425 ++found;
1426
b2e465d6 1427 // Find the proper version to use.
648e3cb4
AL
1428 if (_config->FindB("APT::Cache::AllVersions","true") == true)
1429 {
1430 pkgCache::VerIterator V;
1431 for (V = Pkg.VersionList(); V.end() == false; V++)
1432 {
1433 if (DisplayRecord(V) == false)
1434 return false;
1435 }
1436 }
1437 else
1438 {
b2e465d6 1439 pkgCache::VerIterator V = Plcy.GetCandidateVer(Pkg);
648e3cb4
AL
1440 if (V.end() == true || V.FileList().end() == true)
1441 continue;
1442 if (DisplayRecord(V) == false)
1443 return false;
1444 }
7e2e2d5d 1445 }
9d366c89
AL
1446
1447 if (found > 0)
1448 return true;
1449 return _error->Error(_("No packages found"));
7c1133fe
AL
1450}
1451 /*}}}*/
1452// ShowPkgNames - Show package names /*{{{*/
1453// ---------------------------------------------------------------------
1454/* This does a prefix match on the first argument */
1455bool ShowPkgNames(CommandLine &CmdL)
1456{
1457 pkgCache &Cache = *GCache;
1458 pkgCache::PkgIterator I = Cache.PkgBegin();
1459 bool All = _config->FindB("APT::Cache::AllNames","false");
1460
1461 if (CmdL.FileList[1] != 0)
1462 {
1463 for (;I.end() != true; I++)
1464 {
1465 if (All == false && I->VersionList == 0)
1466 continue;
1467
1468 if (strncmp(I.Name(),CmdL.FileList[1],strlen(CmdL.FileList[1])) == 0)
1469 cout << I.Name() << endl;
1470 }
1471
1472 return true;
1473 }
1474
1475 // Show all pkgs
1476 for (;I.end() != true; I++)
1477 {
1478 if (All == false && I->VersionList == 0)
1479 continue;
1480 cout << I.Name() << endl;
1481 }
1482
7e2e2d5d
AL
1483 return true;
1484}
1485 /*}}}*/
f8f410f5
AL
1486// ShowSrcPackage - Show source package records /*{{{*/
1487// ---------------------------------------------------------------------
1488/* */
1489bool ShowSrcPackage(CommandLine &CmdL)
1490{
1491 pkgSourceList List;
1492 List.ReadMainList();
1493
1494 // Create the text record parsers
1495 pkgSrcRecords SrcRecs(List);
1496 if (_error->PendingError() == true)
1497 return false;
1498
1499 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
1500 {
aaee8293
AL
1501 SrcRecs.Restart();
1502
f8f410f5
AL
1503 pkgSrcRecords::Parser *Parse;
1504 while ((Parse = SrcRecs.Find(*I,false)) != 0)
b2e465d6 1505 cout << Parse->AsStr() << endl;;
f8f410f5 1506 }
af87ab54
AL
1507 return true;
1508}
1509 /*}}}*/
1510// Policy - Show the results of the preferences file /*{{{*/
1511// ---------------------------------------------------------------------
1512/* */
1513bool Policy(CommandLine &CmdL)
1514{
1515 if (SrcList == 0)
1516 return _error->Error("Generate must be enabled for this function");
1517
1518 pkgCache &Cache = *GCache;
1519 pkgPolicy Plcy(&Cache);
e68ca100 1520 if (ReadPinFile(Plcy) == false || ReadPinDir(Plcy) == false)
af87ab54
AL
1521 return false;
1522
1523 // Print out all of the package files
1524 if (CmdL.FileList[1] == 0)
1525 {
db0db9fe 1526 cout << _("Package files:") << endl;
af87ab54
AL
1527 for (pkgCache::PkgFileIterator F = Cache.FileBegin(); F.end() == false; F++)
1528 {
1529 // Locate the associated index files so we can derive a description
1530 pkgIndexFile *Indx;
1531 if (SrcList->FindIndex(F,Indx) == false &&
1532 _system->FindIndex(F,Indx) == false)
1533 return _error->Error(_("Cache is out of sync, can't x-ref a package file"));
78acd650
MV
1534
1535 printf("%4i %s\n",
af87ab54
AL
1536 Plcy.GetPriority(F),Indx->Describe(true).c_str());
1537
1538 // Print the reference information for the package
1539 string Str = F.RelStr();
1540 if (Str.empty() == false)
1541 printf(" release %s\n",F.RelStr().c_str());
1542 if (F.Site() != 0 && F.Site()[0] != 0)
1543 printf(" origin %s\n",F.Site());
1544 }
1545
1546 // Show any packages have explicit pins
db0db9fe 1547 cout << _("Pinned packages:") << endl;
af87ab54
AL
1548 pkgCache::PkgIterator I = Cache.PkgBegin();
1549 for (;I.end() != true; I++)
1550 {
1551 if (Plcy.GetPriority(I) == 0)
1552 continue;
1553
1554 // Print the package name and the version we are forcing to
1555 cout << " " << I.Name() << " -> ";
1556
1557 pkgCache::VerIterator V = Plcy.GetMatch(I);
1558 if (V.end() == true)
1559 cout << _("(not found)") << endl;
1560 else
1561 cout << V.VerStr() << endl;
1562 }
1563
1564 return true;
1565 }
1566
1567 // Print out detailed information for each package
1568 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
1569 {
1570 pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
1571 if (Pkg.end() == true)
1572 {
1573 _error->Warning(_("Unable to locate package %s"),*I);
1574 continue;
1575 }
1576
1577 cout << Pkg.Name() << ":" << endl;
1578
1579 // Installed version
1580 cout << _(" Installed: ");
1581 if (Pkg->CurrentVer == 0)
1582 cout << _("(none)") << endl;
1583 else
1584 cout << Pkg.CurrentVer().VerStr() << endl;
1585
1586 // Candidate Version
1587 cout << _(" Candidate: ");
1588 pkgCache::VerIterator V = Plcy.GetCandidateVer(Pkg);
1589 if (V.end() == true)
1590 cout << _("(none)") << endl;
1591 else
1592 cout << V.VerStr() << endl;
1593
1594 // Pinned version
1595 if (Plcy.GetPriority(Pkg) != 0)
1596 {
db0db9fe 1597 cout << _(" Package pin: ");
af87ab54
AL
1598 V = Plcy.GetMatch(Pkg);
1599 if (V.end() == true)
1600 cout << _("(not found)") << endl;
1601 else
1602 cout << V.VerStr() << endl;
1603 }
1604
1605 // Show the priority tables
db0db9fe 1606 cout << _(" Version table:") << endl;
af87ab54
AL
1607 for (V = Pkg.VersionList(); V.end() == false; V++)
1608 {
1609 if (Pkg.CurrentVer() == V)
1610 cout << " *** " << V.VerStr();
1611 else
1612 cout << " " << V.VerStr();
1613 cout << " " << Plcy.GetPriority(Pkg) << endl;
1614 for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; VF++)
1615 {
1616 // Locate the associated index files so we can derive a description
1617 pkgIndexFile *Indx;
1618 if (SrcList->FindIndex(VF.File(),Indx) == false &&
1619 _system->FindIndex(VF.File(),Indx) == false)
1620 return _error->Error(_("Cache is out of sync, can't x-ref a package file"));
1621 printf(_(" %4i %s\n"),Plcy.GetPriority(VF.File()),
1622 Indx->Describe(true).c_str());
1623 }
1624 }
1625 }
1626
f8f410f5
AL
1627 return true;
1628}
bd3d53ef
AL
1629 /*}}}*/
1630// Madison - Look a bit like katie's madison /*{{{*/
1631// ---------------------------------------------------------------------
1632/* */
1633bool Madison(CommandLine &CmdL)
1634{
1635 if (SrcList == 0)
1636 return _error->Error("Generate must be enabled for this function");
1637
1638 SrcList->ReadMainList();
1639
1640 pkgCache &Cache = *GCache;
1641
03cd434b
MV
1642 // Create the src text record parsers and ignore errors about missing
1643 // deb-src lines that are generated from pkgSrcRecords::pkgSrcRecords
bd3d53ef
AL
1644 pkgSrcRecords SrcRecs(*SrcList);
1645 if (_error->PendingError() == true)
03cd434b 1646 _error->Discard();
bd3d53ef
AL
1647
1648 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
1649 {
1650 pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
1651
1652 if (Pkg.end() == false)
1653 {
1654 for (pkgCache::VerIterator V = Pkg.VersionList(); V.end() == false; V++)
1655 {
1656 for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; VF++)
1657 {
a0e710af
AL
1658// This might be nice, but wouldn't uniquely identify the source -mdz
1659// if (VF.File().Archive() != 0)
1660// {
1661// cout << setw(10) << Pkg.Name() << " | " << setw(10) << V.VerStr() << " | "
1662// << VF.File().Archive() << endl;
1663// }
1664
1665 // Locate the associated index files so we can derive a description
1666 for (pkgSourceList::const_iterator S = SrcList->begin(); S != SrcList->end(); S++)
bd3d53ef 1667 {
7db98ffc
MZ
1668 vector<pkgIndexFile *> *Indexes = (*S)->GetIndexFiles();
1669 for (vector<pkgIndexFile *>::const_iterator IF = Indexes->begin();
1670 IF != Indexes->end(); IF++)
1671 {
1672 if ((*IF)->FindInCache(*(VF.File().Cache())) == VF.File())
1673 {
1674 cout << setw(10) << Pkg.Name() << " | " << setw(10) << V.VerStr() << " | "
1675 << (*IF)->Describe(true) << endl;
1676 }
1677 }
bd3d53ef
AL
1678 }
1679 }
1680 }
1681 }
1682
1683
1684 SrcRecs.Restart();
1685 pkgSrcRecords::Parser *SrcParser;
1686 while ((SrcParser = SrcRecs.Find(*I,false)) != 0)
1687 {
1688 // Maybe support Release info here too eventually
1689 cout << setw(10) << SrcParser->Package() << " | "
1690 << setw(10) << SrcParser->Version() << " | "
1691 << SrcParser->Index().Describe(true) << endl;
1692 }
1693 }
1694
1695 return true;
1696}
f8f410f5 1697 /*}}}*/
880e9be4
AL
1698// GenCaches - Call the main cache generator /*{{{*/
1699// ---------------------------------------------------------------------
1700/* */
b0b4efb9 1701bool GenCaches(CommandLine &Cmd)
880e9be4 1702{
0a8e3465
AL
1703 OpTextProgress Progress(*_config);
1704
880e9be4 1705 pkgSourceList List;
b2e465d6
AL
1706 if (List.ReadMainList() == false)
1707 return false;
0a8e3465 1708 return pkgMakeStatusCache(List,Progress);
880e9be4
AL
1709}
1710 /*}}}*/
e1b74f61
AL
1711// ShowHelp - Show a help screen /*{{{*/
1712// ---------------------------------------------------------------------
1713/* */
b0b4efb9 1714bool ShowHelp(CommandLine &Cmd)
e1b74f61 1715{
5b28c804
OS
1716 ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,VERSION,
1717 COMMON_ARCH,__DATE__,__TIME__);
e1b74f61 1718
b13af988
AL
1719 if (_config->FindB("version") == true)
1720 return true;
1721
b2e465d6
AL
1722 cout <<
1723 _("Usage: apt-cache [options] command\n"
b9d2ece3 1724 " apt-cache [options] add file1 [file2 ...]\n"
b2e465d6 1725 " apt-cache [options] showpkg pkg1 [pkg2 ...]\n"
2d425135 1726 " apt-cache [options] showsrc pkg1 [pkg2 ...]\n"
b2e465d6
AL
1727 "\n"
1728 "apt-cache is a low-level tool used to manipulate APT's binary\n"
1729 "cache files, and query information from them\n"
1730 "\n"
1731 "Commands:\n"
bac2e715 1732 " add - Add a package file to the source cache\n"
b2e465d6
AL
1733 " gencaches - Build both the package and source cache\n"
1734 " showpkg - Show some general information for a single package\n"
2d425135 1735 " showsrc - Show source records\n"
b2e465d6
AL
1736 " stats - Show some basic statistics\n"
1737 " dump - Show the entire file in a terse form\n"
1738 " dumpavail - Print an available file to stdout\n"
1739 " unmet - Show unmet dependencies\n"
b2e465d6
AL
1740 " search - Search the package list for a regex pattern\n"
1741 " show - Show a readable record for the package\n"
1742 " depends - Show raw dependency information for a package\n"
eba2b51d 1743 " rdepends - Show reverse dependency information for a package\n"
2c120e24
EL
1744 " pkgnames - List the names of all packages in the system\n"
1745 " dotty - Generate package graphs for GraphViz\n"
fff4b7f3 1746 " xvcg - Generate package graphs for xvcg\n"
eba05d54 1747 " policy - Show policy settings\n"
b2e465d6
AL
1748 "\n"
1749 "Options:\n"
1750 " -h This help text.\n"
1751 " -p=? The package cache.\n"
1752 " -s=? The source cache.\n"
1753 " -q Disable progress indicator.\n"
1754 " -i Show only important deps for the unmet command.\n"
1755 " -c=? Read this configuration file\n"
a2884e32 1756 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
b2e465d6
AL
1757 "See the apt-cache(8) and apt.conf(5) manual pages for more information.\n");
1758 return true;
e1b74f61
AL
1759}
1760 /*}}}*/
0a8e3465
AL
1761// CacheInitialize - Initialize things for apt-cache /*{{{*/
1762// ---------------------------------------------------------------------
1763/* */
1764void CacheInitialize()
1765{
1766 _config->Set("quiet",0);
1767 _config->Set("help",false);
1768}
1769 /*}}}*/
92fcbfc1 1770int main(int argc,const char *argv[]) /*{{{*/
1164783d 1771{
08e8f724
AL
1772 CommandLine::Args Args[] = {
1773 {'h',"help","help",0},
04aa15a8 1774 {'v',"version","version",0},
e1b74f61
AL
1775 {'p',"pkg-cache","Dir::Cache::pkgcache",CommandLine::HasArg},
1776 {'s',"src-cache","Dir::Cache::srcpkgcache",CommandLine::HasArg},
1777 {'q',"quiet","quiet",CommandLine::IntLevel},
76fbce56 1778 {'i',"important","APT::Cache::Important",0},
7e2e2d5d 1779 {'f',"full","APT::Cache::ShowFull",0},
b2e465d6 1780 {'g',"generate","APT::Cache::Generate",0},
648e3cb4 1781 {'a',"all-versions","APT::Cache::AllVersions",0},
fe6fc1c2
AL
1782 {'n',"names-only","APT::Cache::NamesOnly",0},
1783 {0,"all-names","APT::Cache::AllNames",0},
b2e465d6 1784 {0,"recurse","APT::Cache::RecurseDepends",0},
e1b74f61
AL
1785 {'c',"config-file",0,CommandLine::ConfigFile},
1786 {'o',"option",0,CommandLine::ArbItem},
fe6fc1c2 1787 {0,"installed","APT::Cache::Installed",0},
08e8f724 1788 {0,0,0,0}};
b0b4efb9
AL
1789 CommandLine::Dispatch CmdsA[] = {{"help",&ShowHelp},
1790 {"add",&DoAdd},
1791 {"gencaches",&GenCaches},
f8f410f5 1792 {"showsrc",&ShowSrcPackage},
b0b4efb9
AL
1793 {0,0}};
1794 CommandLine::Dispatch CmdsB[] = {{"showpkg",&DumpPackage},
1795 {"stats",&Stats},
1796 {"dump",&Dump},
1797 {"dumpavail",&DumpAvail},
1798 {"unmet",&UnMet},
9dbb421f 1799 {"search",&Search},
349cd3b8 1800 {"depends",&Depends},
eba2b51d 1801 {"rdepends",&RDepends},
3e94da1b 1802 {"dotty",&Dotty},
fff4b7f3 1803 {"xvcg",&XVcg},
7e2e2d5d 1804 {"show",&ShowPackage},
7c1133fe 1805 {"pkgnames",&ShowPkgNames},
af87ab54 1806 {"policy",&Policy},
bd3d53ef 1807 {"madison",&Madison},
b0b4efb9 1808 {0,0}};
0a8e3465
AL
1809
1810 CacheInitialize();
67111687
AL
1811
1812 // Set up gettext support
1813 setlocale(LC_ALL,"");
1814 textdomain(PACKAGE);
1815
e1b74f61
AL
1816 // Parse the command line and initialize the package library
1817 CommandLine CmdL(Args,_config);
b2e465d6
AL
1818 if (pkgInitConfig(*_config) == false ||
1819 CmdL.Parse(argc,argv) == false ||
1820 pkgInitSystem(*_config,_system) == false)
08e8f724
AL
1821 {
1822 _error->DumpErrors();
1823 return 100;
1164783d 1824 }
8efa2a3b 1825
e1b74f61
AL
1826 // See if the help should be shown
1827 if (_config->FindB("help") == true ||
1828 CmdL.FileSize() == 0)
b2e465d6
AL
1829 {
1830 ShowHelp(CmdL);
1831 return 0;
1832 }
1833
a9a5908d 1834 // Deal with stdout not being a tty
a3f6ea20 1835 if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1)
a9a5908d
AL
1836 _config->Set("quiet","1");
1837
b0b4efb9 1838 if (CmdL.DispatchArg(CmdsA,false) == false && _error->PendingError() == false)
4b1b89c5 1839 {
2a3f3893 1840 MMap *Map = 0;
b2e465d6 1841 if (_config->FindB("APT::Cache::Generate",true) == false)
4b1b89c5
AL
1842 {
1843 Map = new MMap(*new FileFd(_config->FindFile("Dir::Cache::pkgcache"),
1844 FileFd::ReadOnly),MMap::Public|MMap::ReadOnly);
1845 }
1846 else
1847 {
1848 // Open the cache file
af87ab54
AL
1849 SrcList = new pkgSourceList;
1850 SrcList->ReadMainList();
f8f410f5 1851
4b1b89c5
AL
1852 // Generate it and map it
1853 OpProgress Prog;
af87ab54 1854 pkgMakeStatusCache(*SrcList,Prog,&Map,true);
4b1b89c5
AL
1855 }
1856
b0b4efb9 1857 if (_error->PendingError() == false)
1164783d 1858 {
b2e465d6 1859 pkgCache Cache(Map);
b0b4efb9
AL
1860 GCache = &Cache;
1861 if (_error->PendingError() == false)
1862 CmdL.DispatchArg(CmdsB);
803fafcb
AL
1863 }
1864 delete Map;
1164783d
AL
1865 }
1866
1867 // Print any errors or warnings found during parsing
1868 if (_error->empty() == false)
1869 {
0a8e3465 1870 bool Errors = _error->PendingError();
1164783d 1871 _error->DumpErrors();
0a8e3465 1872 return Errors == true?100:0;
1164783d
AL
1873 }
1874
1875 return 0;
1876}
92fcbfc1 1877 /*}}}*/