]>
git.saurik.com Git - apt.git/blob - cmdline/apt-cache.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-cache.cc,v 1.42 1999/12/09 07:32:45 jgg Exp $
4 /* ######################################################################
6 apt-cache - Manages the cache files
8 apt-cache provides some functions fo manipulating the cache files.
9 It uses the command line interface common to all the APT tools. The
10 only really usefull function right now is dumpavail which is used
11 by the dselect method. Everything else is meant as a debug aide.
13 Returns 100 on failure, 0 on success.
15 ##################################################################### */
17 // Include Files /*{{{*/
18 #include <apt-pkg/error.h>
19 #include <apt-pkg/pkgcachegen.h>
20 #include <apt-pkg/deblistparser.h>
21 #include <apt-pkg/init.h>
22 #include <apt-pkg/progress.h>
23 #include <apt-pkg/sourcelist.h>
24 #include <apt-pkg/cmndline.h>
25 #include <apt-pkg/strutl.h>
26 #include <apt-pkg/pkgrecords.h>
27 #include <apt-pkg/srcrecords.h>
38 // UnMet - Show unmet dependencies /*{{{*/
39 // ---------------------------------------------------------------------
41 bool UnMet(CommandLine
&CmdL
)
43 pkgCache
&Cache
= *GCache
;
44 bool Important
= _config
->FindB("APT::Cache::Important",false);
46 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
48 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
51 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() == false;)
54 pkgCache::DepIterator Start
;
55 pkgCache::DepIterator End
;
58 /* cout << "s: Check " << Start.TargetPkg().Name() << ',' <<
59 End.TargetPkg().Name() << endl;*/
61 // Skip conflicts and replaces
62 if (End
->Type
!= pkgCache::Dep::PreDepends
&&
63 End
->Type
!= pkgCache::Dep::Depends
&&
64 End
->Type
!= pkgCache::Dep::Suggests
&&
65 End
->Type
!= pkgCache::Dep::Recommends
)
68 // Important deps only
69 if (Important
== true)
70 if (End
->Type
!= pkgCache::Dep::PreDepends
&&
71 End
->Type
!= pkgCache::Dep::Depends
)
74 // Verify the or group
76 pkgCache::DepIterator RealStart
= Start
;
79 // See if this dep is Ok
80 pkgCache::Version
**VList
= Start
.AllTargets();
101 cout
<< "Package " << P
.Name() << " version " <<
102 V
.VerStr() << " has an unmet dep:" << endl
;
105 // Print out the dep type
106 cout
<< " " << End
.DepType() << ": ";
112 cout
<< Start
.TargetPkg().Name();
113 if (Start
.TargetVer() != 0)
114 cout
<< " (" << Start
.CompType() << " " << Start
.TargetVer() <<
130 // DumpPackage - Show a dump of a package record /*{{{*/
131 // ---------------------------------------------------------------------
133 bool DumpPackage(CommandLine
&CmdL
)
135 pkgCache
&Cache
= *GCache
;
136 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
138 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
139 if (Pkg
.end() == true)
141 _error
->Warning("Unable to locate package %s",*I
);
145 cout
<< "Package: " << Pkg
.Name() << endl
;
146 cout
<< "Versions: ";
147 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
149 cout
<< Cur
.VerStr();
150 for (pkgCache::VerFileIterator Vf
= Cur
.FileList(); Vf
.end() == false; Vf
++)
151 cout
<< "(" << Vf
.File().FileName() << ")";
157 cout
<< "Reverse Depends: " << endl
;
158 for (pkgCache::DepIterator D
= Pkg
.RevDependsList(); D
.end() != true; D
++)
159 cout
<< " " << D
.ParentPkg().Name() << ',' << D
.TargetPkg().Name() << endl
;
161 cout
<< "Dependencies: " << endl
;
162 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
164 cout
<< Cur
.VerStr() << " - ";
165 for (pkgCache::DepIterator Dep
= Cur
.DependsList(); Dep
.end() != true; Dep
++)
166 cout
<< Dep
.TargetPkg().Name() << " (" << (int)Dep
->CompareOp
<< " " << Dep
.TargetVer() << ") ";
170 cout
<< "Provides: " << endl
;
171 for (pkgCache::VerIterator Cur
= Pkg
.VersionList(); Cur
.end() != true; Cur
++)
173 cout
<< Cur
.VerStr() << " - ";
174 for (pkgCache::PrvIterator Prv
= Cur
.ProvidesList(); Prv
.end() != true; Prv
++)
175 cout
<< Prv
.ParentPkg().Name() << " ";
178 cout
<< "Reverse Provides: " << endl
;
179 for (pkgCache::PrvIterator Prv
= Pkg
.ProvidesList(); Prv
.end() != true; Prv
++)
180 cout
<< Prv
.OwnerPkg().Name() << " " << Prv
.OwnerVer().VerStr() << endl
;
186 // Stats - Dump some nice statistics /*{{{*/
187 // ---------------------------------------------------------------------
189 bool Stats(CommandLine
&Cmd
)
191 pkgCache
&Cache
= *GCache
;
192 cout
<< "Total Package Names : " << Cache
.Head().PackageCount
<< " (" <<
193 SizeToStr(Cache
.Head().PackageCount
*Cache
.Head().PackageSz
) << ')' << endl
;
194 pkgCache::PkgIterator I
= Cache
.PkgBegin();
201 for (;I
.end() != true; I
++)
203 if (I
->VersionList
!= 0 && I
->ProvidesList
== 0)
209 if (I
->VersionList
!= 0 && I
->ProvidesList
!= 0)
215 if (I
->VersionList
== 0 && I
->ProvidesList
!= 0)
218 if (I
.ProvidesList()->NextProvides
== 0)
226 if (I
->VersionList
== 0 && I
->ProvidesList
== 0)
232 cout
<< " Normal Packages: " << Normal
<< endl
;
233 cout
<< " Pure Virtual Packages: " << Virtual
<< endl
;
234 cout
<< " Single Virtual Packages: " << DVirt
<< endl
;
235 cout
<< " Mixed Virtual Packages: " << NVirt
<< endl
;
236 cout
<< " Missing: " << Missing
<< endl
;
238 cout
<< "Total Distinct Versions: " << Cache
.Head().VersionCount
<< " (" <<
239 SizeToStr(Cache
.Head().VersionCount
*Cache
.Head().VersionSz
) << ')' << endl
;
240 cout
<< "Total Dependencies: " << Cache
.Head().DependsCount
<< " (" <<
241 SizeToStr(Cache
.Head().DependsCount
*Cache
.Head().DependencySz
) << ')' << endl
;
243 cout
<< "Total Ver/File relations: " << Cache
.Head().VerFileCount
<< " (" <<
244 SizeToStr(Cache
.Head().VerFileCount
*Cache
.Head().VerFileSz
) << ')' << endl
;
245 cout
<< "Total Provides Mappings: " << Cache
.Head().ProvidesCount
<< " (" <<
246 SizeToStr(Cache
.Head().ProvidesCount
*Cache
.Head().ProvidesSz
) << ')' << endl
;
249 unsigned long Size
= 0;
250 unsigned long Count
= 0;
251 for (pkgCache::StringItem
*I
= Cache
.StringItemP
+ Cache
.Head().StringList
;
252 I
!= Cache
.StringItemP
; I
= Cache
.StringItemP
+ I
->NextItem
)
255 Size
+= strlen(Cache
.StrP
+ I
->String
);
257 cout
<< "Total Globbed Strings: " << Count
<< " (" << SizeToStr(Size
) << ')' << endl
;
259 unsigned long Slack
= 0;
260 for (int I
= 0; I
!= 7; I
++)
261 Slack
+= Cache
.Head().Pools
[I
].ItemSize
*Cache
.Head().Pools
[I
].Count
;
262 cout
<< "Total Slack space: " << SizeToStr(Slack
) << endl
;
264 unsigned long Total
= 0;
265 Total
= Slack
+ Size
+ Cache
.Head().DependsCount
*Cache
.Head().DependencySz
+
266 Cache
.Head().VersionCount
*Cache
.Head().VersionSz
+
267 Cache
.Head().PackageCount
*Cache
.Head().PackageSz
+
268 Cache
.Head().VerFileCount
*Cache
.Head().VerFileSz
+
269 Cache
.Head().ProvidesCount
*Cache
.Head().ProvidesSz
;
270 cout
<< "Total Space Accounted for: " << SizeToStr(Total
) << endl
;
275 // Check - Check some things about the cache /*{{{*/
276 // ---------------------------------------------------------------------
277 /* Debug aide mostly */
278 bool Check(CommandLine
&Cmd
)
280 pkgCache
&Cache
= *GCache
;
281 pkgCache::PkgIterator Pkg
= Cache
.PkgBegin();
282 for (;Pkg
.end() != true; Pkg
++)
284 if (Pkg
.Section() == 0 && Pkg
->VersionList
!= 0)
285 cout
<< "Bad section " << Pkg
.Name() << endl
;
287 for (pkgCache::VerIterator Cur
= Pkg
.VersionList();
288 Cur
.end() != true; Cur
++)
290 if (Cur
->Priority
< 1 || Cur
->Priority
> 5)
291 cout
<< "Bad prio " << Pkg
.Name() << ',' << Cur
.VerStr() << " == " << (int)Cur
->Priority
<< endl
;
297 // Dump - show everything /*{{{*/
298 // ---------------------------------------------------------------------
300 bool Dump(CommandLine
&Cmd
)
302 pkgCache
&Cache
= *GCache
;
303 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
305 cout
<< "Package: " << P
.Name() << endl
;
306 for (pkgCache::VerIterator V
= P
.VersionList(); V
.end() == false; V
++)
308 cout
<< " Version: " << V
.VerStr() << endl
;
309 cout
<< " File: " << V
.FileList().File().FileName() << endl
;
310 for (pkgCache::DepIterator D
= V
.DependsList(); D
.end() == false; D
++)
311 cout
<< " Depends: " << D
.TargetPkg().Name() << ' ' << D
.TargetVer() << endl
;
315 for (pkgCache::PkgFileIterator
F(Cache
); F
.end() == false; F
++)
317 cout
<< "File: " << F
.FileName() << endl
;
318 cout
<< " Size: " << F
->Size
<< endl
;
319 cout
<< " ID: " << F
->ID
<< endl
;
320 cout
<< " Flags: " << F
->Flags
<< endl
;
321 cout
<< " Time: " << TimeRFC1123(F
->mtime
) << endl
;
322 cout
<< " Archive: " << F
.Archive() << endl
;
323 cout
<< " Component: " << F
.Component() << endl
;
324 cout
<< " Version: " << F
.Version() << endl
;
325 cout
<< " Origin: " << F
.Origin() << endl
;
326 cout
<< " Label: " << F
.Label() << endl
;
327 cout
<< " Architecture: " << F
.Architecture() << endl
;
333 // DumpAvail - Print out the available list /*{{{*/
334 // ---------------------------------------------------------------------
335 /* This is needed to make dpkg --merge happy */
336 bool DumpAvail(CommandLine
&Cmd
)
338 pkgCache
&Cache
= *GCache
;
339 unsigned char *Buffer
= new unsigned char[Cache
.HeaderP
->MaxVerFileSize
];
341 for (pkgCache::PkgFileIterator I
= Cache
.FileBegin(); I
.end() == false; I
++)
343 if ((I
->Flags
& pkgCache::Flag::NotSource
) != 0)
346 if (I
.IsOk() == false)
349 return _error
->Error("Package file %s is out of sync.",I
.FileName());
352 FileFd
PkgF(I
.FileName(),FileFd::ReadOnly
);
353 if (_error
->PendingError() == true)
359 /* Write all of the records from this package file, we search the entire
360 structure to find them */
361 for (pkgCache::PkgIterator P
= Cache
.PkgBegin(); P
.end() == false; P
++)
363 // Find the proper version to use. We should probably use the DepCache.
364 pkgCache::VerIterator V
= Cache
.GetCandidateVer(P
,false);
366 if (V
.end() == true || V
.FileList().File() != I
)
369 // Read the record and then write it out again.
370 if (PkgF
.Seek(V
.FileList()->Offset
) == false ||
371 PkgF
.Read(Buffer
,V
.FileList()->Size
) == false ||
372 write(STDOUT_FILENO
,Buffer
,V
.FileList()->Size
) != V
.FileList()->Size
)
383 // Depends - Print out a dependency tree /*{{{*/
384 // ---------------------------------------------------------------------
386 bool Depends(CommandLine
&CmdL
)
388 pkgCache
&Cache
= *GCache
;
390 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
392 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
393 if (Pkg
.end() == true)
395 _error
->Warning("Unable to locate package %s",*I
);
399 pkgCache::VerIterator Ver
= Pkg
.VersionList();
400 if (Ver
.end() == true)
402 cout
<< '<' << Pkg
.Name() << '>' << endl
;
406 cout
<< Pkg
.Name() << endl
;
408 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
410 if ((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
)
416 pkgCache::PkgIterator Trg
= D
.TargetPkg();
417 if (Trg
->VersionList
== 0)
418 cout
<< D
.DepType() << ": <" << Trg
.Name() << ">" << endl
;
420 cout
<< D
.DepType() << ": " << Trg
.Name() << endl
;
422 // Display all solutions
423 pkgCache::Version
**List
= D
.AllTargets();
424 for (pkgCache::Version
**I
= List
; *I
!= 0; I
++)
426 pkgCache::VerIterator
V(Cache
,*I
);
427 if (V
!= Cache
.VerP
+ V
.ParentPkg()->VersionList
||
428 V
->ParentPkg
== D
->Package
)
430 cout
<< " " << V
.ParentPkg().Name() << endl
;
439 // DoAdd - Perform an adding operation /*{{{*/
440 // ---------------------------------------------------------------------
442 bool DoAdd(CommandLine
&CmdL
)
444 // Make sure there is at least one argument
445 if (CmdL
.FileSize() <= 1)
446 return _error
->Error("You must give at least one file name");
449 FileFd
CacheF(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::WriteAny
);
450 if (_error
->PendingError() == true)
453 DynamicMMap
Map(CacheF
,MMap::Public
);
454 if (_error
->PendingError() == true)
457 OpTextProgress
Progress(*_config
);
458 pkgCacheGenerator
Gen(Map
,Progress
);
459 if (_error
->PendingError() == true)
462 unsigned long Length
= CmdL
.FileSize() - 1;
463 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
465 Progress
.OverallProgress(I
- CmdL
.FileList
,Length
,1,"Generating cache");
466 Progress
.SubProgress(Length
);
469 FileFd
TagF(*I
,FileFd::ReadOnly
);
470 debListParser
Parser(TagF
);
471 if (_error
->PendingError() == true)
472 return _error
->Error("Problem opening %s",*I
);
474 if (Gen
.SelectFile(*I
) == false)
475 return _error
->Error("Problem with SelectFile");
477 if (Gen
.MergeList(Parser
) == false)
478 return _error
->Error("Problem with MergeList");
482 GCache
= &Gen
.GetCache();
488 // DisplayRecord - Displays the complete record for the package /*{{{*/
489 // ---------------------------------------------------------------------
490 /* This displays the package record from the proper package index file.
491 It is not used by DumpAvail for performance reasons. */
492 bool DisplayRecord(pkgCache::VerIterator V
)
494 // Find an appropriate file
495 pkgCache::VerFileIterator Vf
= V
.FileList();
496 for (; Vf
.end() == false; Vf
++)
497 if ((Vf
.File()->Flags
& pkgCache::Flag::NotSource
) == 0)
499 if (Vf
.end() == true)
502 // Check and load the package list file
503 pkgCache::PkgFileIterator I
= Vf
.File();
504 if (I
.IsOk() == false)
505 return _error
->Error("Package file %s is out of sync.",I
.FileName());
507 FileFd
PkgF(I
.FileName(),FileFd::ReadOnly
);
508 if (_error
->PendingError() == true)
511 // Read the record and then write it out again.
512 unsigned char *Buffer
= new unsigned char[GCache
->HeaderP
->MaxVerFileSize
];
513 if (PkgF
.Seek(V
.FileList()->Offset
) == false ||
514 PkgF
.Read(Buffer
,V
.FileList()->Size
) == false ||
515 write(STDOUT_FILENO
,Buffer
,V
.FileList()->Size
) != V
.FileList()->Size
)
526 // Search - Perform a search /*{{{*/
527 // ---------------------------------------------------------------------
528 /* This searches the package names and pacakge descriptions for a pattern */
529 bool Search(CommandLine
&CmdL
)
531 pkgCache
&Cache
= *GCache
;
532 bool ShowFull
= _config
->FindB("APT::Cache::ShowFull",false);
533 bool NamesOnly
= _config
->FindB("APT::Cache::NamesOnly",false);
535 // Make sure there is at least one argument
536 if (CmdL
.FileSize() != 2)
537 return _error
->Error("You must give exactly one pattern");
539 // Compile the regex pattern
541 if (regcomp(&Pattern
,CmdL
.FileList
[1],REG_EXTENDED
| REG_ICASE
|
543 return _error
->Error("Regex compilation error");
545 // Create the text record parser
546 pkgRecords
Recs(Cache
);
547 if (_error
->PendingError() == true)
550 // Search package names
551 pkgCache::PkgIterator I
= Cache
.PkgBegin();
552 for (;I
.end() != true; I
++)
554 // We search against the install version as that makes the most sense..
555 pkgCache::VerIterator V
= Cache
.GetCandidateVer(I
);
559 pkgRecords::Parser
&P
= Recs
.Lookup(V
.FileList());
561 if (regexec(&Pattern
,I
.Name(),0,0,0) == 0 ||
562 (NamesOnly
== false &&
563 regexec(&Pattern
,P
.LongDesc().c_str(),0,0,0) == 0))
565 if (ShowFull
== true)
568 cout
<< I
.Name() << " - " << P
.ShortDesc() << endl
;
576 // ShowPackage - Dump the package record to the screen /*{{{*/
577 // ---------------------------------------------------------------------
579 bool ShowPackage(CommandLine
&CmdL
)
581 pkgCache
&Cache
= *GCache
;
582 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
584 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(*I
);
585 if (Pkg
.end() == true)
587 _error
->Warning("Unable to locate package %s",*I
);
591 // Find the proper version to use. We should probably use the DepCache.
592 if (_config
->FindB("APT::Cache::AllVersions","true") == true)
594 pkgCache::VerIterator V
;
595 for (V
= Pkg
.VersionList(); V
.end() == false; V
++)
597 if (DisplayRecord(V
) == false)
603 pkgCache::VerIterator V
= Cache
.GetCandidateVer(Pkg
);
604 if (V
.end() == true || V
.FileList().end() == true)
606 if (DisplayRecord(V
) == false)
613 // ShowPkgNames - Show package names /*{{{*/
614 // ---------------------------------------------------------------------
615 /* This does a prefix match on the first argument */
616 bool ShowPkgNames(CommandLine
&CmdL
)
618 pkgCache
&Cache
= *GCache
;
619 pkgCache::PkgIterator I
= Cache
.PkgBegin();
620 bool All
= _config
->FindB("APT::Cache::AllNames","false");
622 if (CmdL
.FileList
[1] != 0)
624 for (;I
.end() != true; I
++)
626 if (All
== false && I
->VersionList
== 0)
629 if (strncmp(I
.Name(),CmdL
.FileList
[1],strlen(CmdL
.FileList
[1])) == 0)
630 cout
<< I
.Name() << endl
;
637 for (;I
.end() != true; I
++)
639 if (All
== false && I
->VersionList
== 0)
641 cout
<< I
.Name() << endl
;
647 // ShowSrcPackage - Show source package records /*{{{*/
648 // ---------------------------------------------------------------------
650 bool ShowSrcPackage(CommandLine
&CmdL
)
655 // Create the text record parsers
656 pkgSrcRecords
SrcRecs(List
);
657 if (_error
->PendingError() == true)
660 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
664 pkgSrcRecords::Parser
*Parse
;
665 while ((Parse
= SrcRecs
.Find(*I
,false)) != 0)
666 cout
<< Parse
->AsStr();
671 // GenCaches - Call the main cache generator /*{{{*/
672 // ---------------------------------------------------------------------
674 bool GenCaches(CommandLine
&Cmd
)
676 OpTextProgress
Progress(*_config
);
680 return pkgMakeStatusCache(List
,Progress
);
683 // ShowHelp - Show a help screen /*{{{*/
684 // ---------------------------------------------------------------------
686 bool ShowHelp(CommandLine
&Cmd
)
688 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
689 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
690 if (_config
->FindB("version") == true)
693 cout
<< "Usage: apt-cache [options] command" << endl
;
694 cout
<< " apt-cache [options] add file1 [file1 ...]" << endl
;
695 cout
<< " apt-cache [options] showpkg pkg1 [pkg2 ...]" << endl
;
697 cout
<< "apt-cache is a low-level tool used to manipulate APT's binary" << endl
;
698 cout
<< "cache files stored in " << _config
->FindFile("Dir::Cache") << endl
;
699 cout
<< "It is not meant for ordinary use only as a debug aide." << endl
;
701 cout
<< "Commands:" << endl
;
702 cout
<< " add - Add an package file to the source cache" << endl
;
703 cout
<< " gencaches - Build both the package and source cache" << endl
;
704 cout
<< " showpkg - Show some general information for a single package" << endl
;
705 cout
<< " stats - Show some basic statistics" << endl
;
706 cout
<< " dump - Show the entire file in a terse form" << endl
;
707 cout
<< " dumpavail - Print an available file to stdout" << endl
;
708 cout
<< " unmet - Show unmet dependencies" << endl
;
709 cout
<< " check - Check the cache a bit" << endl
;
710 cout
<< " search - Search the package list for a regex pattern" << endl
;
711 cout
<< " show - Show a readable record for the package" << endl
;
712 cout
<< " depends - Show raw dependency information for a package" << endl
;
713 cout
<< " pkgnames - List the names of all packages" << endl
;
715 cout
<< "Options:" << endl
;
716 cout
<< " -h This help text." << endl
;
717 cout
<< " -p=? The package cache. [" << _config
->FindFile("Dir::Cache::pkgcache") << ']' << endl
;
718 cout
<< " -s=? The source cache. [" << _config
->FindFile("Dir::Cache::srcpkgcache") << ']' << endl
;
719 cout
<< " -q Disable progress indicator." << endl
;
720 cout
<< " -i Show only important deps for the unmet command." << endl
;
721 cout
<< " -c=? Read this configuration file" << endl
;
722 cout
<< " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp" << endl
;
723 cout
<< "See the apt-cache(8) and apt.conf(5) manual pages for more information." << endl
;
727 // CacheInitialize - Initialize things for apt-cache /*{{{*/
728 // ---------------------------------------------------------------------
730 void CacheInitialize()
732 _config
->Set("quiet",0);
733 _config
->Set("help",false);
737 int main(int argc
,const char *argv
[])
739 CommandLine::Args Args
[] = {
740 {'h',"help","help",0},
741 {'v',"version","version",0},
742 {'p',"pkg-cache","Dir::Cache::pkgcache",CommandLine::HasArg
},
743 {'s',"src-cache","Dir::Cache::srcpkgcache",CommandLine::HasArg
},
744 {'q',"quiet","quiet",CommandLine::IntLevel
},
745 {'i',"important","APT::Cache::Important",0},
746 {'f',"full","APT::Cache::ShowFull",0},
747 {'g',"no-generate","APT::Cache::NoGenerate",0},
748 {'a',"all-versions","APT::Cache::AllVersions",0},
749 {0,"names-only","APT::Cache::NamesOnly",0},
750 {0,"all-names","APT::Cache::AllNames",0},
751 {'c',"config-file",0,CommandLine::ConfigFile
},
752 {'o',"option",0,CommandLine::ArbItem
},
754 CommandLine::Dispatch CmdsA
[] = {{"help",&ShowHelp
},
756 {"gencaches",&GenCaches
},
757 {"showsrc",&ShowSrcPackage
},
759 CommandLine::Dispatch CmdsB
[] = {{"showpkg",&DumpPackage
},
762 {"dumpavail",&DumpAvail
},
766 {"depends",&Depends
},
767 {"show",&ShowPackage
},
768 {"pkgnames",&ShowPkgNames
},
773 // Parse the command line and initialize the package library
774 CommandLine
CmdL(Args
,_config
);
775 if (pkgInitialize(*_config
) == false ||
776 CmdL
.Parse(argc
,argv
) == false)
778 _error
->DumpErrors();
782 // See if the help should be shown
783 if (_config
->FindB("help") == true ||
784 CmdL
.FileSize() == 0)
785 return ShowHelp(CmdL
);
787 // Deal with stdout not being a tty
788 if (ttyname(STDOUT_FILENO
) == 0 && _config
->FindI("quiet",0) < 1)
789 _config
->Set("quiet","1");
791 if (CmdL
.DispatchArg(CmdsA
,false) == false && _error
->PendingError() == false)
794 if (_config
->FindB("APT::Cache::NoGenerate",false) == true)
796 Map
= new MMap(*new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),
797 FileFd::ReadOnly
),MMap::Public
|MMap::ReadOnly
);
801 // Open the cache file
805 // Generate it and map it
807 Map
= pkgMakeStatusCacheMem(List
,Prog
);
810 if (_error
->PendingError() == false)
812 pkgCache
Cache(*Map
);
814 if (_error
->PendingError() == false)
815 CmdL
.DispatchArg(CmdsB
);
820 // Print any errors or warnings found during parsing
821 if (_error
->empty() == false)
823 bool Errors
= _error
->PendingError();
824 _error
->DumpErrors();
825 return Errors
== true?100:0;