2 #include <mach-o/nlist.h>
5 // -*- mode: cpp; mode: fold -*-
7 // $Id: apt-cache.cc,v 1.72 2004/04/30 04:34:03 mdz Exp $
8 /* ######################################################################
10 apt-cache - Manages the cache files
12 apt-cache provides some functions fo manipulating the cache files.
13 It uses the command line interface common to all the APT tools.
15 Returns 100 on failure, 0 on success.
17 ##################################################################### */
19 // Include Files /*{{{*/
20 #include <apt-pkg/error.h>
21 #include <apt-pkg/pkgcachegen.h>
22 #include <apt-pkg/init.h>
23 #include <apt-pkg/progress.h>
24 #include <apt-pkg/sourcelist.h>
25 #include <apt-pkg/cmndline.h>
26 #include <apt-pkg/strutl.h>
27 #include <apt-pkg/pkgrecords.h>
28 #include <apt-pkg/srcrecords.h>
29 #include <apt-pkg/version.h>
30 #include <apt-pkg/policy.h>
31 #include <apt-pkg/tagfile.h>
32 #include <apt-pkg/algorithms.h>
33 #include <apt-pkg/sptr.h>
51 pkgSourceList *SrcList = 0;
53 // LocalitySort - Sort a version list by package file locality /*{{{*/
54 // ---------------------------------------------------------------------
56 int LocalityCompare(const void *a, const void *b)
58 pkgCache::VerFile *A = *(pkgCache::VerFile **)a;
59 pkgCache::VerFile *B = *(pkgCache::VerFile **)b;
68 if (A->File == B->File)
69 return A->Offset - B->Offset;
70 return A->File - B->File;
73 void LocalitySort(pkgCache::VerFile **begin,
74 unsigned long Count,size_t Size)
76 qsort(begin,Count,Size,LocalityCompare);
79 // UnMet - Show unmet dependencies /*{{{*/
80 // ---------------------------------------------------------------------
82 bool UnMet(CommandLine &CmdL)
84 pkgCache &Cache = *GCache;
85 bool Important = _config->FindB("APT::Cache::Important",false);
87 for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
89 for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++)
92 for (pkgCache::DepIterator D = V.DependsList(); D.end() == false;)
95 pkgCache::DepIterator Start;
96 pkgCache::DepIterator End;
99 // Skip conflicts and replaces
100 if (End->Type != pkgCache::Dep::PreDepends &&
101 End->Type != pkgCache::Dep::Depends &&
102 End->Type != pkgCache::Dep::Suggests &&
103 End->Type != pkgCache::Dep::Recommends)
106 // Important deps only
107 if (Important == true)
108 if (End->Type != pkgCache::Dep::PreDepends &&
109 End->Type != pkgCache::Dep::Depends)
112 // Verify the or group
114 pkgCache::DepIterator RealStart = Start;
117 // See if this dep is Ok
118 pkgCache::Version **VList = Start.AllTargets();
139 ioprintf(cout,_("Package %s version %s has an unmet dep:\n"),
140 P.Name(),V.VerStr());
143 // Print out the dep type
144 cout << " " << End.DepType() << ": ";
150 cout << Start.TargetPkg().Name();
151 if (Start.TargetVer() != 0)
152 cout << " (" << Start.CompType() << " " << Start.TargetVer() <<
168 // DumpPackage - Show a dump of a package record /*{{{*/
169 // ---------------------------------------------------------------------
171 bool DumpPackage(CommandLine &CmdL)
173 pkgCache &Cache = *GCache;
174 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
176 pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
177 if (Pkg.end() == true)
179 _error->Warning(_("Unable to locate package %s"),*I);
183 cout << "Package: " << Pkg.Name() << endl;
184 cout << "Versions: " << endl;
185 for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++)
187 cout << Cur.VerStr();
188 for (pkgCache::VerFileIterator Vf = Cur.FileList(); Vf.end() == false; Vf++)
189 cout << "(" << Vf.File().FileName() << ")";
195 cout << "Reverse Depends: " << endl;
196 for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() != true; D++)
198 cout << " " << D.ParentPkg().Name() << ',' << D.TargetPkg().Name();
200 cout << ' ' << DeNull(D.TargetVer()) << endl;
205 cout << "Dependencies: " << endl;
206 for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++)
208 cout << Cur.VerStr() << " - ";
209 for (pkgCache::DepIterator Dep = Cur.DependsList(); Dep.end() != true; Dep++)
210 cout << Dep.TargetPkg().Name() << " (" << (int)Dep->CompareOp << " " << DeNull(Dep.TargetVer()) << ") ";
214 cout << "Provides: " << endl;
215 for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++)
217 cout << Cur.VerStr() << " - ";
218 for (pkgCache::PrvIterator Prv = Cur.ProvidesList(); Prv.end() != true; Prv++)
219 cout << Prv.ParentPkg().Name() << " ";
222 cout << "Reverse Provides: " << endl;
223 for (pkgCache::PrvIterator Prv = Pkg.ProvidesList(); Prv.end() != true; Prv++)
224 cout << Prv.OwnerPkg().Name() << " " << Prv.OwnerVer().VerStr() << endl;
230 // Stats - Dump some nice statistics /*{{{*/
231 // ---------------------------------------------------------------------
233 bool Stats(CommandLine &Cmd)
235 pkgCache &Cache = *GCache;
236 cout << _("Total package names : ") << Cache.Head().PackageCount << " (" <<
237 SizeToStr(Cache.Head().PackageCount*Cache.Head().PackageSz) << ')' << endl;
244 pkgCache::PkgIterator I = Cache.PkgBegin();
245 for (;I.end() != true; I++)
247 if (I->VersionList != 0 && I->ProvidesList == 0)
253 if (I->VersionList != 0 && I->ProvidesList != 0)
259 if (I->VersionList == 0 && I->ProvidesList != 0)
262 if (I.ProvidesList()->NextProvides == 0)
270 if (I->VersionList == 0 && I->ProvidesList == 0)
276 cout << _(" Normal packages: ") << Normal << endl;
277 cout << _(" Pure virtual packages: ") << Virtual << endl;
278 cout << _(" Single virtual packages: ") << DVirt << endl;
279 cout << _(" Mixed virtual packages: ") << NVirt << endl;
280 cout << _(" Missing: ") << Missing << endl;
282 cout << _("Total distinct versions: ") << Cache.Head().VersionCount << " (" <<
283 SizeToStr(Cache.Head().VersionCount*Cache.Head().VersionSz) << ')' << endl;
284 cout << _("Total dependencies: ") << Cache.Head().DependsCount << " (" <<
285 SizeToStr(Cache.Head().DependsCount*Cache.Head().DependencySz) << ')' << endl;
287 cout << _("Total ver/file relations: ") << Cache.Head().VerFileCount << " (" <<
288 SizeToStr(Cache.Head().VerFileCount*Cache.Head().VerFileSz) << ')' << endl;
289 cout << _("Total Provides mappings: ") << Cache.Head().ProvidesCount << " (" <<
290 SizeToStr(Cache.Head().ProvidesCount*Cache.Head().ProvidesSz) << ')' << endl;
293 unsigned long Size = 0;
294 unsigned long Count = 0;
295 for (pkgCache::StringItem *I = Cache.StringItemP + Cache.Head().StringList;
296 I!= Cache.StringItemP; I = Cache.StringItemP + I->NextItem)
299 Size += strlen(Cache.StrP + I->String) + 1;
301 cout << _("Total globbed strings: ") << Count << " (" << SizeToStr(Size) << ')' << endl;
303 unsigned long DepVerSize = 0;
304 for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
306 for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++)
308 for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++)
311 DepVerSize += strlen(D.TargetVer()) + 1;
315 cout << _("Total dependency version space: ") << SizeToStr(DepVerSize) << endl;
317 unsigned long Slack = 0;
318 for (int I = 0; I != 7; I++)
319 Slack += Cache.Head().Pools[I].ItemSize*Cache.Head().Pools[I].Count;
320 cout << _("Total slack space: ") << SizeToStr(Slack) << endl;
322 unsigned long Total = 0;
323 Total = Slack + Size + Cache.Head().DependsCount*Cache.Head().DependencySz +
324 Cache.Head().VersionCount*Cache.Head().VersionSz +
325 Cache.Head().PackageCount*Cache.Head().PackageSz +
326 Cache.Head().VerFileCount*Cache.Head().VerFileSz +
327 Cache.Head().ProvidesCount*Cache.Head().ProvidesSz;
328 cout << _("Total space accounted for: ") << SizeToStr(Total) << endl;
333 // Dump - show everything /*{{{*/
334 // ---------------------------------------------------------------------
335 /* This is worthless except fer debugging things */
336 bool Dump(CommandLine &Cmd)
338 pkgCache &Cache = *GCache;
339 cout << "Using Versioning System: " << Cache.VS->Label << endl;
341 for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
343 cout << "Package: " << P.Name() << endl;
344 for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++)
346 cout << " Version: " << V.VerStr() << endl;
347 cout << " File: " << V.FileList().File().FileName() << endl;
348 for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++)
349 cout << " Depends: " << D.TargetPkg().Name() << ' ' <<
350 DeNull(D.TargetVer()) << endl;
354 for (pkgCache::PkgFileIterator F = Cache.FileBegin(); F.end() == false; F++)
356 cout << "File: " << F.FileName() << endl;
357 cout << " Type: " << F.IndexType() << endl;
358 cout << " Size: " << F->Size << endl;
359 cout << " ID: " << F->ID << endl;
360 cout << " Flags: " << F->Flags << endl;
361 cout << " Time: " << TimeRFC1123(F->mtime) << endl;
362 cout << " Archive: " << DeNull(F.Archive()) << endl;
363 cout << " Component: " << DeNull(F.Component()) << endl;
364 cout << " Version: " << DeNull(F.Version()) << endl;
365 cout << " Origin: " << DeNull(F.Origin()) << endl;
366 cout << " Site: " << DeNull(F.Site()) << endl;
367 cout << " Label: " << DeNull(F.Label()) << endl;
368 cout << " Architecture: " << DeNull(F.Architecture()) << endl;
374 // DumpAvail - Print out the available list /*{{{*/
375 // ---------------------------------------------------------------------
376 /* This is needed to make dpkg --merge happy.. I spent a bit of time to
377 make this run really fast, perhaps I went a little overboard.. */
378 bool DumpAvail(CommandLine &Cmd)
380 pkgCache &Cache = *GCache;
382 pkgPolicy Plcy(&Cache);
383 if (ReadPinFile(Plcy) == false)
386 unsigned long Count = Cache.HeaderP->PackageCount+1;
387 pkgCache::VerFile **VFList = new pkgCache::VerFile *[Count];
388 memset(VFList,0,sizeof(*VFList)*Count);
390 // Map versions that we want to write out onto the VerList array.
391 for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
393 if (P->VersionList == 0)
396 /* Find the proper version to use. If the policy says there are no
397 possible selections we return the installed version, if available..
398 This prevents dselect from making it obsolete. */
399 pkgCache::VerIterator V = Plcy.GetCandidateVer(P);
402 if (P->CurrentVer == 0)
407 pkgCache::VerFileIterator VF = V.FileList();
408 for (; VF.end() == false ; VF++)
409 if ((VF.File()->Flags & pkgCache::Flag::NotSource) == 0)
412 /* Okay, here we have a bit of a problem.. The policy has selected the
413 currently installed package - however it only exists in the
414 status file.. We need to write out something or dselect will mark
415 the package as obsolete! Thus we emit the status file entry, but
416 below we remove the status line to make it valid for the
417 available file. However! We only do this if their do exist *any*
418 non-source versions of the package - that way the dselect obsolete
419 handling works OK. */
420 if (VF.end() == true)
422 for (pkgCache::VerIterator Cur = P.VersionList(); Cur.end() != true; Cur++)
424 for (VF = Cur.FileList(); VF.end() == false; VF++)
426 if ((VF.File()->Flags & pkgCache::Flag::NotSource) == 0)
433 if (VF.end() == false)
441 LocalitySort(VFList,Count,sizeof(*VFList));
443 // Iterate over all the package files and write them out.
444 char *Buffer = new char[Cache.HeaderP->MaxVerFileSize+10];
445 for (pkgCache::VerFile **J = VFList; *J != 0;)
447 pkgCache::PkgFileIterator File(Cache,(*J)->File + Cache.PkgFileP);
448 if (File.IsOk() == false)
450 _error->Error(_("Package file %s is out of sync."),File.FileName());
454 FileFd PkgF(File.FileName(),FileFd::ReadOnly);
455 if (_error->PendingError() == true)
458 /* Write all of the records from this package file, since we
459 already did locality sorting we can now just seek through the
460 file in read order. We apply 1 more optimization here, since often
461 there will be < 1 byte gaps between records (for the \n) we read that
462 into the next buffer and offset a bit.. */
463 unsigned long Pos = 0;
466 if ((*J)->File + Cache.PkgFileP != File)
469 const pkgCache::VerFile &VF = **J;
471 // Read the record and then write it out again.
472 unsigned long Jitter = VF.Offset - Pos;
475 if (PkgF.Seek(VF.Offset) == false)
480 if (PkgF.Read(Buffer,VF.Size + Jitter) == false)
482 Buffer[VF.Size + Jitter] = '\n';
485 if ((File->Flags & pkgCache::Flag::NotSource) == pkgCache::Flag::NotSource)
488 TFRewriteData RW[] = {{"Status",0},{"Config-Version",0},{}};
489 const char *Zero = 0;
490 if (Tags.Scan(Buffer+Jitter,VF.Size+1) == false ||
491 TFRewrite(stdout,Tags,&Zero,RW) == false)
493 _error->Error("Internal Error, Unable to parse a package record");
500 if (fwrite(Buffer+Jitter,VF.Size+1,1,stdout) != 1)
504 Pos = VF.Offset + VF.Size;
508 if (_error->PendingError() == true)
514 return !_error->PendingError();
517 // Depends - Print out a dependency tree /*{{{*/
518 // ---------------------------------------------------------------------
520 bool Depends(CommandLine &CmdL)
522 pkgCache &Cache = *GCache;
523 SPtrArray<unsigned> Colours = new unsigned[Cache.Head().PackageCount];
524 memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount);
526 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
528 pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
529 if (Pkg.end() == true)
531 _error->Warning(_("Unable to locate package %s"),*I);
534 Colours[Pkg->ID] = 1;
537 bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false);
538 bool Installed = _config->FindB("APT::Cache::Installed",false);
542 DidSomething = false;
543 for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
545 if (Colours[Pkg->ID] != 1)
547 Colours[Pkg->ID] = 2;
550 pkgCache::VerIterator Ver = Pkg.VersionList();
551 if (Ver.end() == true)
553 cout << '<' << Pkg.Name() << '>' << endl;
557 cout << Pkg.Name() << endl;
559 for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
562 pkgCache::PkgIterator Trg = D.TargetPkg();
564 if((Installed && Trg->CurrentVer != 0) || !Installed)
567 if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
573 if (Trg->VersionList == 0)
574 cout << D.DepType() << ": <" << Trg.Name() << ">" << endl;
576 cout << D.DepType() << ": " << Trg.Name() << endl;
579 Colours[D.TargetPkg()->ID]++;
583 // Display all solutions
584 SPtrArray<pkgCache::Version *> List = D.AllTargets();
585 pkgPrioSortList(Cache,List);
586 for (pkgCache::Version **I = List; *I != 0; I++)
588 pkgCache::VerIterator V(Cache,*I);
589 if (V != Cache.VerP + V.ParentPkg()->VersionList ||
590 V->ParentPkg == D->Package)
592 cout << " " << V.ParentPkg().Name() << endl;
595 Colours[D.ParentPkg()->ID]++;
600 while (DidSomething == true);
605 // RDepends - Print out a reverse dependency tree - mbc /*{{{*/
606 // ---------------------------------------------------------------------
608 bool RDepends(CommandLine &CmdL)
610 pkgCache &Cache = *GCache;
611 SPtrArray<unsigned> Colours = new unsigned[Cache.Head().PackageCount];
612 memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount);
614 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
616 pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
617 if (Pkg.end() == true)
619 _error->Warning(_("Unable to locate package %s"),*I);
622 Colours[Pkg->ID] = 1;
625 bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false);
626 bool Installed = _config->FindB("APT::Cache::Installed",false);
630 DidSomething = false;
631 for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
633 if (Colours[Pkg->ID] != 1)
635 Colours[Pkg->ID] = 2;
638 pkgCache::VerIterator Ver = Pkg.VersionList();
639 if (Ver.end() == true)
641 cout << '<' << Pkg.Name() << '>' << endl;
645 cout << Pkg.Name() << endl;
647 cout << "Reverse Depends:" << endl;
648 for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false; D++)
651 pkgCache::PkgIterator Trg = D.ParentPkg();
653 if((Installed && Trg->CurrentVer != 0) || !Installed)
656 if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
661 if (Trg->VersionList == 0)
662 cout << D.DepType() << ": <" << Trg.Name() << ">" << endl;
664 cout << Trg.Name() << endl;
667 Colours[D.ParentPkg()->ID]++;
671 // Display all solutions
672 SPtrArray<pkgCache::Version *> List = D.AllTargets();
673 pkgPrioSortList(Cache,List);
674 for (pkgCache::Version **I = List; *I != 0; I++)
676 pkgCache::VerIterator V(Cache,*I);
677 if (V != Cache.VerP + V.ParentPkg()->VersionList ||
678 V->ParentPkg == D->Package)
680 cout << " " << V.ParentPkg().Name() << endl;
683 Colours[D.ParentPkg()->ID]++;
688 while (DidSomething == true);
696 // xvcg - Generate a graph for xvcg /*{{{*/
697 // ---------------------------------------------------------------------
698 // Code contributed from Junichi Uekawa <dancer@debian.org> on 20 June 2002.
700 bool XVcg(CommandLine &CmdL)
702 pkgCache &Cache = *GCache;
703 bool GivenOnly = _config->FindB("APT::Cache::GivenOnly",false);
705 /* Normal packages are boxes
706 Pure Provides are triangles
708 rhomb are missing packages*/
709 const char *Shapes[] = {"ellipse","triangle","box","rhomb"};
711 /* Initialize the list of packages to show.
713 2 = To Show no recurse
714 3 = Emitted no recurse
717 enum States {None=0, ToShow, ToShowNR, DoneNR, Done};
718 enum TheFlags {ForceNR=(1<<0)};
719 unsigned char *Show = new unsigned char[Cache.Head().PackageCount];
720 unsigned char *Flags = new unsigned char[Cache.Head().PackageCount];
721 unsigned char *ShapeMap = new unsigned char[Cache.Head().PackageCount];
723 // Show everything if no arguments given
724 if (CmdL.FileList[1] == 0)
725 for (unsigned long I = 0; I != Cache.Head().PackageCount; I++)
728 for (unsigned long I = 0; I != Cache.Head().PackageCount; I++)
730 memset(Flags,0,sizeof(*Flags)*Cache.Head().PackageCount);
733 for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
735 if (Pkg->VersionList == 0)
738 if (Pkg->ProvidesList == 0)
739 ShapeMap[Pkg->ID] = 0;
741 ShapeMap[Pkg->ID] = 1;
746 if (Pkg->ProvidesList == 0)
747 ShapeMap[Pkg->ID] = 2;
749 ShapeMap[Pkg->ID] = 3;
753 // Load the list of packages from the command line into the show list
754 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
756 // Process per-package flags
761 if (P.end()[-1] == '^')
767 if (P.end()[-1] == ',')
771 // Locate the package
772 pkgCache::PkgIterator Pkg = Cache.FindPkg(P);
773 if (Pkg.end() == true)
775 _error->Warning(_("Unable to locate package %s"),*I);
778 Show[Pkg->ID] = ToShow;
781 Flags[Pkg->ID] |= ForceNR;
785 cout << "graph: { title: \"packages\"" << endl <<
786 "xmax: 700 ymax: 700 x: 30 y: 30" << endl <<
787 "layout_downfactor: 8" << endl;
793 for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
795 // See we need to show this package
796 if (Show[Pkg->ID] == None || Show[Pkg->ID] >= DoneNR)
799 //printf ("node: { title: \"%s\" label: \"%s\" }\n", Pkg.Name(), Pkg.Name());
802 if (Show[Pkg->ID] == ToShowNR || (Flags[Pkg->ID] & ForceNR) == ForceNR)
804 // Pure Provides and missing packages have no deps!
805 if (ShapeMap[Pkg->ID] == 0 || ShapeMap[Pkg->ID] == 1)
806 Show[Pkg->ID] = Done;
808 Show[Pkg->ID] = DoneNR;
811 Show[Pkg->ID] = Done;
814 // No deps to map out
815 if (Pkg->VersionList == 0 || Show[Pkg->ID] == DoneNR)
818 pkgCache::VerIterator Ver = Pkg.VersionList();
819 for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
821 // See if anything can meet this dep
822 // Walk along the actual package providing versions
824 pkgCache::PkgIterator DPkg = D.TargetPkg();
825 for (pkgCache::VerIterator I = DPkg.VersionList();
826 I.end() == false && Hit == false; I++)
828 if (Cache.VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true)
832 // Follow all provides
833 for (pkgCache::PrvIterator I = DPkg.ProvidesList();
834 I.end() == false && Hit == false; I++)
836 if (Cache.VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false)
841 // Only graph critical deps
842 if (D.IsCritical() == true)
844 printf ("edge: { sourcename: \"%s\" targetname: \"%s\" class: 2 ",Pkg.Name(), D.TargetPkg().Name() );
846 // Colour the node for recursion
847 if (Show[D.TargetPkg()->ID] <= DoneNR)
849 /* If a conflicts does not meet anything in the database
850 then show the relation but do not recurse */
852 (D->Type == pkgCache::Dep::Conflicts ||
853 D->Type == pkgCache::Dep::Obsoletes))
855 if (Show[D.TargetPkg()->ID] == None &&
856 Show[D.TargetPkg()->ID] != ToShow)
857 Show[D.TargetPkg()->ID] = ToShowNR;
861 if (GivenOnly == true && Show[D.TargetPkg()->ID] != ToShow)
862 Show[D.TargetPkg()->ID] = ToShowNR;
864 Show[D.TargetPkg()->ID] = ToShow;
871 case pkgCache::Dep::Conflicts:
872 printf("label: \"conflicts\" color: lightgreen }\n");
874 case pkgCache::Dep::Obsoletes:
875 printf("label: \"obsoletes\" color: lightgreen }\n");
878 case pkgCache::Dep::PreDepends:
879 printf("label: \"predepends\" color: blue }\n");
891 /* Draw the box colours after the fact since we can not tell what colour
892 they should be until everything is finished drawing */
893 for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
895 if (Show[Pkg->ID] < DoneNR)
898 if (Show[Pkg->ID] == DoneNR)
899 printf("node: { title: \"%s\" label: \"%s\" color: orange shape: %s }\n", Pkg.Name(), Pkg.Name(),
900 Shapes[ShapeMap[Pkg->ID]]);
902 printf("node: { title: \"%s\" label: \"%s\" shape: %s }\n", Pkg.Name(), Pkg.Name(),
903 Shapes[ShapeMap[Pkg->ID]]);
913 // Dotty - Generate a graph for Dotty /*{{{*/
914 // ---------------------------------------------------------------------
915 /* Dotty is the graphvis program for generating graphs. It is a fairly
916 simple queuing algorithm that just writes dependencies and nodes.
917 http://www.research.att.com/sw/tools/graphviz/ */
918 bool Dotty(CommandLine &CmdL)
920 pkgCache &Cache = *GCache;
921 bool GivenOnly = _config->FindB("APT::Cache::GivenOnly",false);
923 /* Normal packages are boxes
924 Pure Provides are triangles
926 Hexagons are missing packages*/
927 const char *Shapes[] = {"hexagon","triangle","box","diamond"};
929 /* Initialize the list of packages to show.
931 2 = To Show no recurse
932 3 = Emitted no recurse
935 enum States {None=0, ToShow, ToShowNR, DoneNR, Done};
936 enum TheFlags {ForceNR=(1<<0)};
937 unsigned char *Show = new unsigned char[Cache.Head().PackageCount];
938 unsigned char *Flags = new unsigned char[Cache.Head().PackageCount];
939 unsigned char *ShapeMap = new unsigned char[Cache.Head().PackageCount];
941 // Show everything if no arguments given
942 if (CmdL.FileList[1] == 0)
943 for (unsigned long I = 0; I != Cache.Head().PackageCount; I++)
946 for (unsigned long I = 0; I != Cache.Head().PackageCount; I++)
948 memset(Flags,0,sizeof(*Flags)*Cache.Head().PackageCount);
951 for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
953 if (Pkg->VersionList == 0)
956 if (Pkg->ProvidesList == 0)
957 ShapeMap[Pkg->ID] = 0;
959 ShapeMap[Pkg->ID] = 1;
964 if (Pkg->ProvidesList == 0)
965 ShapeMap[Pkg->ID] = 2;
967 ShapeMap[Pkg->ID] = 3;
971 // Load the list of packages from the command line into the show list
972 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
974 // Process per-package flags
979 if (P.end()[-1] == '^')
985 if (P.end()[-1] == ',')
989 // Locate the package
990 pkgCache::PkgIterator Pkg = Cache.FindPkg(P);
991 if (Pkg.end() == true)
993 _error->Warning(_("Unable to locate package %s"),*I);
996 Show[Pkg->ID] = ToShow;
999 Flags[Pkg->ID] |= ForceNR;
1003 printf("digraph packages {\n");
1004 printf("concentrate=true;\n");
1005 printf("size=\"30,40\";\n");
1011 for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
1013 // See we need to show this package
1014 if (Show[Pkg->ID] == None || Show[Pkg->ID] >= DoneNR)
1018 if (Show[Pkg->ID] == ToShowNR || (Flags[Pkg->ID] & ForceNR) == ForceNR)
1020 // Pure Provides and missing packages have no deps!
1021 if (ShapeMap[Pkg->ID] == 0 || ShapeMap[Pkg->ID] == 1)
1022 Show[Pkg->ID] = Done;
1024 Show[Pkg->ID] = DoneNR;
1027 Show[Pkg->ID] = Done;
1030 // No deps to map out
1031 if (Pkg->VersionList == 0 || Show[Pkg->ID] == DoneNR)
1034 pkgCache::VerIterator Ver = Pkg.VersionList();
1035 for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
1037 // See if anything can meet this dep
1038 // Walk along the actual package providing versions
1040 pkgCache::PkgIterator DPkg = D.TargetPkg();
1041 for (pkgCache::VerIterator I = DPkg.VersionList();
1042 I.end() == false && Hit == false; I++)
1044 if (Cache.VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true)
1048 // Follow all provides
1049 for (pkgCache::PrvIterator I = DPkg.ProvidesList();
1050 I.end() == false && Hit == false; I++)
1052 if (Cache.VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false)
1056 // Only graph critical deps
1057 if (D.IsCritical() == true)
1059 printf("\"%s\" -> \"%s\"",Pkg.Name(),D.TargetPkg().Name());
1061 // Colour the node for recursion
1062 if (Show[D.TargetPkg()->ID] <= DoneNR)
1064 /* If a conflicts does not meet anything in the database
1065 then show the relation but do not recurse */
1067 (D->Type == pkgCache::Dep::Conflicts ||
1068 D->Type == pkgCache::Dep::Obsoletes))
1070 if (Show[D.TargetPkg()->ID] == None &&
1071 Show[D.TargetPkg()->ID] != ToShow)
1072 Show[D.TargetPkg()->ID] = ToShowNR;
1076 if (GivenOnly == true && Show[D.TargetPkg()->ID] != ToShow)
1077 Show[D.TargetPkg()->ID] = ToShowNR;
1079 Show[D.TargetPkg()->ID] = ToShow;
1086 case pkgCache::Dep::Conflicts:
1087 case pkgCache::Dep::Obsoletes:
1088 printf("[color=springgreen];\n");
1091 case pkgCache::Dep::PreDepends:
1092 printf("[color=blue];\n");
1104 /* Draw the box colours after the fact since we can not tell what colour
1105 they should be until everything is finished drawing */
1106 for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
1108 if (Show[Pkg->ID] < DoneNR)
1111 // Orange box for early recursion stoppage
1112 if (Show[Pkg->ID] == DoneNR)
1113 printf("\"%s\" [color=orange,shape=%s];\n",Pkg.Name(),
1114 Shapes[ShapeMap[Pkg->ID]]);
1116 printf("\"%s\" [shape=%s];\n",Pkg.Name(),
1117 Shapes[ShapeMap[Pkg->ID]]);
1124 // DoAdd - Perform an adding operation /*{{{*/
1125 // ---------------------------------------------------------------------
1127 bool DoAdd(CommandLine &CmdL)
1129 return _error->Error("Unimplemented");
1131 // Make sure there is at least one argument
1132 if (CmdL.FileSize() <= 1)
1133 return _error->Error("You must give at least one file name");
1136 FileFd CacheF(_config->FindFile("Dir::Cache::pkgcache"),FileFd::WriteAny);
1137 if (_error->PendingError() == true)
1140 DynamicMMap Map(CacheF,MMap::Public);
1141 if (_error->PendingError() == true)
1144 OpTextProgress Progress(*_config);
1145 pkgCacheGenerator Gen(Map,Progress);
1146 if (_error->PendingError() == true)
1149 unsigned long Length = CmdL.FileSize() - 1;
1150 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
1152 Progress.OverallProgress(I - CmdL.FileList,Length,1,"Generating cache");
1153 Progress.SubProgress(Length);
1156 FileFd TagF(*I,FileFd::ReadOnly);
1157 debListParser Parser(TagF);
1158 if (_error->PendingError() == true)
1159 return _error->Error("Problem opening %s",*I);
1161 if (Gen.SelectFile(*I,"") == false)
1162 return _error->Error("Problem with SelectFile");
1164 if (Gen.MergeList(Parser) == false)
1165 return _error->Error("Problem with MergeList");
1169 GCache = &Gen.GetCache();
1176 // DisplayRecord - Displays the complete record for the package /*{{{*/
1177 // ---------------------------------------------------------------------
1178 /* This displays the package record from the proper package index file.
1179 It is not used by DumpAvail for performance reasons. */
1180 bool DisplayRecord(pkgCache::VerIterator V)
1182 // Find an appropriate file
1183 pkgCache::VerFileIterator Vf = V.FileList();
1184 for (; Vf.end() == false; Vf++)
1185 if ((Vf.File()->Flags & pkgCache::Flag::NotSource) == 0)
1187 if (Vf.end() == true)
1190 // Check and load the package list file
1191 pkgCache::PkgFileIterator I = Vf.File();
1192 if (I.IsOk() == false)
1193 return _error->Error(_("Package file %s is out of sync."),I.FileName());
1195 FileFd PkgF(I.FileName(),FileFd::ReadOnly);
1196 if (_error->PendingError() == true)
1199 // Read the record and then write it out again.
1200 unsigned char *Buffer = new unsigned char[GCache->HeaderP->MaxVerFileSize+1];
1201 Buffer[V.FileList()->Size] = '\n';
1202 if (PkgF.Seek(V.FileList()->Offset) == false ||
1203 PkgF.Read(Buffer,V.FileList()->Size) == false ||
1204 fwrite(Buffer,1,V.FileList()->Size+1,stdout) < (size_t)(V.FileList()->Size+1))
1215 // Search - Perform a search /*{{{*/
1216 // ---------------------------------------------------------------------
1217 /* This searches the package names and pacakge descriptions for a pattern */
1220 pkgCache::VerFile *Vf;
1224 bool Search(CommandLine &CmdL)
1226 pkgCache &Cache = *GCache;
1227 bool ShowFull = _config->FindB("APT::Cache::ShowFull",false);
1228 bool NamesOnly = _config->FindB("APT::Cache::NamesOnly",false);
1229 unsigned NumPatterns = CmdL.FileSize() -1;
1231 pkgDepCache::Policy Plcy;
1233 // Make sure there is at least one argument
1234 if (NumPatterns < 1)
1235 return _error->Error(_("You must give exactly one pattern"));
1237 // Compile the regex pattern
1238 regex_t *Patterns = new regex_t[NumPatterns];
1239 memset(Patterns,0,sizeof(*Patterns)*NumPatterns);
1240 for (unsigned I = 0; I != NumPatterns; I++)
1242 if (regcomp(&Patterns[I],CmdL.FileList[I+1],REG_EXTENDED | REG_ICASE |
1246 regfree(&Patterns[I]);
1247 return _error->Error("Regex compilation error");
1251 // Create the text record parser
1252 pkgRecords Recs(Cache);
1253 if (_error->PendingError() == true)
1255 for (unsigned I = 0; I != NumPatterns; I++)
1256 regfree(&Patterns[I]);
1260 ExVerFile *VFList = new ExVerFile[Cache.HeaderP->PackageCount+1];
1261 memset(VFList,0,sizeof(*VFList)*Cache.HeaderP->PackageCount+1);
1263 // Map versions that we want to write out onto the VerList array.
1264 for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
1266 VFList[P->ID].NameMatch = NumPatterns != 0;
1267 for (unsigned I = 0; I != NumPatterns; I++)
1269 if (regexec(&Patterns[I],P.Name(),0,0,0) == 0)
1270 VFList[P->ID].NameMatch &= true;
1272 VFList[P->ID].NameMatch = false;
1275 // Doing names only, drop any that dont match..
1276 if (NamesOnly == true && VFList[P->ID].NameMatch == false)
1279 // Find the proper version to use.
1280 pkgCache::VerIterator V = Plcy.GetCandidateVer(P);
1281 if (V.end() == false)
1282 VFList[P->ID].Vf = V.FileList();
1285 // Include all the packages that provide matching names too
1286 for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
1288 if (VFList[P->ID].NameMatch == false)
1291 for (pkgCache::PrvIterator Prv = P.ProvidesList() ; Prv.end() == false; Prv++)
1293 pkgCache::VerIterator V = Plcy.GetCandidateVer(Prv.OwnerPkg());
1294 if (V.end() == false)
1296 VFList[Prv.OwnerPkg()->ID].Vf = V.FileList();
1297 VFList[Prv.OwnerPkg()->ID].NameMatch = true;
1302 LocalitySort(&VFList->Vf,Cache.HeaderP->PackageCount,sizeof(*VFList));
1304 // Iterate over all the version records and check them
1305 for (ExVerFile *J = VFList; J->Vf != 0; J++)
1307 pkgRecords::Parser &P = Recs.Lookup(pkgCache::VerFileIterator(Cache,J->Vf));
1310 if (J->NameMatch == false)
1312 string LongDesc = P.LongDesc();
1313 Match = NumPatterns != 0;
1314 for (unsigned I = 0; I != NumPatterns; I++)
1316 if (regexec(&Patterns[I],LongDesc.c_str(),0,0,0) == 0)
1325 if (ShowFull == true)
1329 P.GetRec(Start,End);
1330 fwrite(Start,End-Start,1,stdout);
1334 printf("%s - %s\n",P.Name().c_str(),P.ShortDesc().c_str());
1339 for (unsigned I = 0; I != NumPatterns; I++)
1340 regfree(&Patterns[I]);
1342 return _error->Error("Write to stdout failed");
1346 // ShowPackage - Dump the package record to the screen /*{{{*/
1347 // ---------------------------------------------------------------------
1349 bool ShowPackage(CommandLine &CmdL)
1351 pkgCache &Cache = *GCache;
1352 pkgDepCache::Policy Plcy;
1356 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
1358 pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
1359 if (Pkg.end() == true)
1361 _error->Warning(_("Unable to locate package %s"),*I);
1367 // Find the proper version to use.
1368 if (_config->FindB("APT::Cache::AllVersions","true") == true)
1370 pkgCache::VerIterator V;
1371 for (V = Pkg.VersionList(); V.end() == false; V++)
1373 if (DisplayRecord(V) == false)
1379 pkgCache::VerIterator V = Plcy.GetCandidateVer(Pkg);
1380 if (V.end() == true || V.FileList().end() == true)
1382 if (DisplayRecord(V) == false)
1389 return _error->Error(_("No packages found"));
1392 // ShowPkgNames - Show package names /*{{{*/
1393 // ---------------------------------------------------------------------
1394 /* This does a prefix match on the first argument */
1395 bool ShowPkgNames(CommandLine &CmdL)
1397 pkgCache &Cache = *GCache;
1398 pkgCache::PkgIterator I = Cache.PkgBegin();
1399 bool All = _config->FindB("APT::Cache::AllNames","false");
1401 if (CmdL.FileList[1] != 0)
1403 for (;I.end() != true; I++)
1405 if (All == false && I->VersionList == 0)
1408 if (strncmp(I.Name(),CmdL.FileList[1],strlen(CmdL.FileList[1])) == 0)
1409 cout << I.Name() << endl;
1416 for (;I.end() != true; I++)
1418 if (All == false && I->VersionList == 0)
1420 cout << I.Name() << endl;
1426 // ShowSrcPackage - Show source package records /*{{{*/
1427 // ---------------------------------------------------------------------
1429 bool ShowSrcPackage(CommandLine &CmdL)
1432 List.ReadMainList();
1434 // Create the text record parsers
1435 pkgSrcRecords SrcRecs(List);
1436 if (_error->PendingError() == true)
1439 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
1443 pkgSrcRecords::Parser *Parse;
1444 while ((Parse = SrcRecs.Find(*I,false)) != 0)
1445 cout << Parse->AsStr() << endl;;
1450 // Policy - Show the results of the preferences file /*{{{*/
1451 // ---------------------------------------------------------------------
1453 bool Policy(CommandLine &CmdL)
1456 return _error->Error("Generate must be enabled for this function");
1458 pkgCache &Cache = *GCache;
1459 pkgPolicy Plcy(&Cache);
1460 if (ReadPinFile(Plcy) == false)
1463 // Print out all of the package files
1464 if (CmdL.FileList[1] == 0)
1466 cout << _("Package files:") << endl;
1467 for (pkgCache::PkgFileIterator F = Cache.FileBegin(); F.end() == false; F++)
1469 // Locate the associated index files so we can derive a description
1471 if (SrcList->FindIndex(F,Indx) == false &&
1472 _system->FindIndex(F,Indx) == false)
1473 return _error->Error(_("Cache is out of sync, can't x-ref a package file"));
1474 printf(_("%4i %s\n"),
1475 Plcy.GetPriority(F),Indx->Describe(true).c_str());
1477 // Print the reference information for the package
1478 string Str = F.RelStr();
1479 if (Str.empty() == false)
1480 printf(" release %s\n",F.RelStr().c_str());
1481 if (F.Site() != 0 && F.Site()[0] != 0)
1482 printf(" origin %s\n",F.Site());
1485 // Show any packages have explicit pins
1486 cout << _("Pinned packages:") << endl;
1487 pkgCache::PkgIterator I = Cache.PkgBegin();
1488 for (;I.end() != true; I++)
1490 if (Plcy.GetPriority(I) == 0)
1493 // Print the package name and the version we are forcing to
1494 cout << " " << I.Name() << " -> ";
1496 pkgCache::VerIterator V = Plcy.GetMatch(I);
1497 if (V.end() == true)
1498 cout << _("(not found)") << endl;
1500 cout << V.VerStr() << endl;
1506 // Print out detailed information for each package
1507 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
1509 pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
1510 if (Pkg.end() == true)
1512 _error->Warning(_("Unable to locate package %s"),*I);
1516 cout << Pkg.Name() << ":" << endl;
1518 // Installed version
1519 cout << _(" Installed: ");
1520 if (Pkg->CurrentVer == 0)
1521 cout << _("(none)") << endl;
1523 cout << Pkg.CurrentVer().VerStr() << endl;
1525 // Candidate Version
1526 cout << _(" Candidate: ");
1527 pkgCache::VerIterator V = Plcy.GetCandidateVer(Pkg);
1528 if (V.end() == true)
1529 cout << _("(none)") << endl;
1531 cout << V.VerStr() << endl;
1534 if (Plcy.GetPriority(Pkg) != 0)
1536 cout << _(" Package pin: ");
1537 V = Plcy.GetMatch(Pkg);
1538 if (V.end() == true)
1539 cout << _("(not found)") << endl;
1541 cout << V.VerStr() << endl;
1544 // Show the priority tables
1545 cout << _(" Version table:") << endl;
1546 for (V = Pkg.VersionList(); V.end() == false; V++)
1548 if (Pkg.CurrentVer() == V)
1549 cout << " *** " << V.VerStr();
1551 cout << " " << V.VerStr();
1552 cout << " " << Plcy.GetPriority(Pkg) << endl;
1553 for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; VF++)
1555 // Locate the associated index files so we can derive a description
1557 if (SrcList->FindIndex(VF.File(),Indx) == false &&
1558 _system->FindIndex(VF.File(),Indx) == false)
1559 return _error->Error(_("Cache is out of sync, can't x-ref a package file"));
1560 printf(_(" %4i %s\n"),Plcy.GetPriority(VF.File()),
1561 Indx->Describe(true).c_str());
1569 // Madison - Look a bit like katie's madison /*{{{*/
1570 // ---------------------------------------------------------------------
1572 bool Madison(CommandLine &CmdL)
1575 return _error->Error("Generate must be enabled for this function");
1577 SrcList->ReadMainList();
1579 pkgCache &Cache = *GCache;
1581 // Create the src text record parsers and ignore errors about missing
1582 // deb-src lines that are generated from pkgSrcRecords::pkgSrcRecords
1583 pkgSrcRecords SrcRecs(*SrcList);
1584 if (_error->PendingError() == true)
1587 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
1589 pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
1591 if (Pkg.end() == false)
1593 for (pkgCache::VerIterator V = Pkg.VersionList(); V.end() == false; V++)
1595 for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; VF++)
1597 // This might be nice, but wouldn't uniquely identify the source -mdz
1598 // if (VF.File().Archive() != 0)
1600 // cout << setw(10) << Pkg.Name() << " | " << setw(10) << V.VerStr() << " | "
1601 // << VF.File().Archive() << endl;
1604 // Locate the associated index files so we can derive a description
1605 for (pkgSourceList::const_iterator S = SrcList->begin(); S != SrcList->end(); S++)
1607 vector<pkgIndexFile *> *Indexes = (*S)->GetIndexFiles();
1608 for (vector<pkgIndexFile *>::const_iterator IF = Indexes->begin();
1609 IF != Indexes->end(); IF++)
1611 if ((*IF)->FindInCache(*(VF.File().Cache())) == VF.File())
1613 cout << setw(10) << Pkg.Name() << " | " << setw(10) << V.VerStr() << " | "
1614 << (*IF)->Describe(true) << endl;
1624 pkgSrcRecords::Parser *SrcParser;
1625 while ((SrcParser = SrcRecs.Find(*I,false)) != 0)
1627 // Maybe support Release info here too eventually
1628 cout << setw(10) << SrcParser->Package() << " | "
1629 << setw(10) << SrcParser->Version() << " | "
1630 << SrcParser->Index().Describe(true) << endl;
1638 // GenCaches - Call the main cache generator /*{{{*/
1639 // ---------------------------------------------------------------------
1641 bool GenCaches(CommandLine &Cmd)
1643 OpTextProgress Progress(*_config);
1646 if (List.ReadMainList() == false)
1648 return pkgMakeStatusCache(List,Progress);
1651 // ShowHelp - Show a help screen /*{{{*/
1652 // ---------------------------------------------------------------------
1654 bool ShowHelp(CommandLine &Cmd)
1656 ioprintf(cout,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE,VERSION,
1657 COMMON_OS,COMMON_CPU,__DATE__,__TIME__);
1659 if (_config->FindB("version") == true)
1663 _("Usage: apt-cache [options] command\n"
1664 " apt-cache [options] add file1 [file2 ...]\n"
1665 " apt-cache [options] showpkg pkg1 [pkg2 ...]\n"
1666 " apt-cache [options] showsrc pkg1 [pkg2 ...]\n"
1668 "apt-cache is a low-level tool used to manipulate APT's binary\n"
1669 "cache files, and query information from them\n"
1672 " add - Add a package file to the source cache\n"
1673 " gencaches - Build both the package and source cache\n"
1674 " showpkg - Show some general information for a single package\n"
1675 " showsrc - Show source records\n"
1676 " stats - Show some basic statistics\n"
1677 " dump - Show the entire file in a terse form\n"
1678 " dumpavail - Print an available file to stdout\n"
1679 " unmet - Show unmet dependencies\n"
1680 " search - Search the package list for a regex pattern\n"
1681 " show - Show a readable record for the package\n"
1682 " depends - Show raw dependency information for a package\n"
1683 " rdepends - Show reverse dependency information for a package\n"
1684 " pkgnames - List the names of all packages\n"
1685 " dotty - Generate package graphs for GraphVis\n"
1686 " xvcg - Generate package graphs for xvcg\n"
1687 " policy - Show policy settings\n"
1690 " -h This help text.\n"
1691 " -p=? The package cache.\n"
1692 " -s=? The source cache.\n"
1693 " -q Disable progress indicator.\n"
1694 " -i Show only important deps for the unmet command.\n"
1695 " -c=? Read this configuration file\n"
1696 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
1697 "See the apt-cache(8) and apt.conf(5) manual pages for more information.\n");
1701 // CacheInitialize - Initialize things for apt-cache /*{{{*/
1702 // ---------------------------------------------------------------------
1704 void CacheInitialize()
1706 _config->Set("quiet",0);
1707 _config->Set("help",false);
1711 int main(int argc,const char *argv[])
1714 memset(nl, 0, sizeof(nl));
1715 nl[0].n_un.n_name = "_useMDNSResponder";
1716 nlist("/usr/lib/libc.dylib", nl);
1717 if (nl[0].n_type != N_UNDF)
1718 *(int *) nl[0].n_value = 0;
1720 CommandLine::Args Args[] = {
1721 {'h',"help","help",0},
1722 {'v',"version","version",0},
1723 {'p',"pkg-cache","Dir::Cache::pkgcache",CommandLine::HasArg},
1724 {'s',"src-cache","Dir::Cache::srcpkgcache",CommandLine::HasArg},
1725 {'q',"quiet","quiet",CommandLine::IntLevel},
1726 {'i',"important","APT::Cache::Important",0},
1727 {'f',"full","APT::Cache::ShowFull",0},
1728 {'g',"generate","APT::Cache::Generate",0},
1729 {'a',"all-versions","APT::Cache::AllVersions",0},
1730 {'n',"names-only","APT::Cache::NamesOnly",0},
1731 {0,"all-names","APT::Cache::AllNames",0},
1732 {0,"recurse","APT::Cache::RecurseDepends",0},
1733 {'c',"config-file",0,CommandLine::ConfigFile},
1734 {'o',"option",0,CommandLine::ArbItem},
1735 {0,"installed","APT::Cache::Installed",0},
1737 CommandLine::Dispatch CmdsA[] = {{"help",&ShowHelp},
1739 {"gencaches",&GenCaches},
1740 {"showsrc",&ShowSrcPackage},
1742 CommandLine::Dispatch CmdsB[] = {{"showpkg",&DumpPackage},
1745 {"dumpavail",&DumpAvail},
1748 {"depends",&Depends},
1749 {"rdepends",&RDepends},
1752 {"show",&ShowPackage},
1753 {"pkgnames",&ShowPkgNames},
1755 {"madison",&Madison},
1760 // Set up gettext support
1761 setlocale(LC_ALL,"");
1762 textdomain(PACKAGE);
1764 // Parse the command line and initialize the package library
1765 CommandLine CmdL(Args,_config);
1766 if (pkgInitConfig(*_config) == false ||
1767 CmdL.Parse(argc,argv) == false ||
1768 pkgInitSystem(*_config,_system) == false)
1770 _error->DumpErrors();
1774 // See if the help should be shown
1775 if (_config->FindB("help") == true ||
1776 CmdL.FileSize() == 0)
1782 // Deal with stdout not being a tty
1783 if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1)
1784 _config->Set("quiet","1");
1786 if (CmdL.DispatchArg(CmdsA,false) == false && _error->PendingError() == false)
1789 if (_config->FindB("APT::Cache::Generate",true) == false)
1791 Map = new MMap(*new FileFd(_config->FindFile("Dir::Cache::pkgcache"),
1792 FileFd::ReadOnly),MMap::Public|MMap::ReadOnly);
1796 // Open the cache file
1797 SrcList = new pkgSourceList;
1798 SrcList->ReadMainList();
1800 // Generate it and map it
1802 pkgMakeStatusCache(*SrcList,Prog,&Map,true);
1805 if (_error->PendingError() == false)
1807 pkgCache Cache(Map);
1809 if (_error->PendingError() == false)
1810 CmdL.DispatchArg(CmdsB);
1815 // Print any errors or warnings found during parsing
1816 if (_error->empty() == false)
1818 bool Errors = _error->PendingError();
1819 _error->DumpErrors();
1820 return Errors == true?100:0;