+ // Find the proper version to use. We should probably use the DepCache.
+ pkgCache::VerIterator V = Cache.GetCandidateVer(Pkg);
+ if (V.end() == true || V.FileList().end() == true)
+ continue;
+ if (DisplayRecord(V) == false)
+ return false;
+ }
+ return true;
+}
+ /*}}}*/
+// GenCaches - Call the main cache generator /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool GenCaches(CommandLine &Cmd)
+{
+ OpTextProgress Progress(*_config);
+
+ pkgSourceList List;
+ List.ReadMainList();
+ return pkgMakeStatusCache(List,Progress);
+}
+ /*}}}*/
+// ShowHelp - Show a help screen /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool ShowHelp(CommandLine &Cmd)
+{
+ cout << PACKAGE << ' ' << VERSION << " for " << ARCHITECTURE <<
+ " compiled on " << __DATE__ << " " << __TIME__ << endl;
+ if (_config->FindB("version") == true)
+ return 100;
+
+ cout << "Usage: apt-cache [options] command" << endl;
+ cout << " apt-cache [options] add file1 [file1 ...]" << endl;
+ cout << " apt-cache [options] showpkg pkg1 [pkg2 ...]" << endl;
+ cout << endl;
+ cout << "apt-cache is a low-level tool used to manipulate APT's binary" << endl;
+ cout << "cache files stored in " << _config->FindFile("Dir::Cache") << endl;
+ cout << "It is not meant for ordinary use only as a debug aide." << endl;
+ cout << endl;
+ cout << "Commands:" << endl;
+ cout << " add - Add an package file to the source cache" << endl;
+ cout << " gencaches - Build both the package and source cache" << endl;
+ cout << " showpkg - Show some general information for a single package" << endl;
+ cout << " stats - Show some basic statistics" << endl;
+ cout << " dump - Show the entire file in a terse form" << endl;
+ cout << " dumpavail - Print an available file to stdout" << endl;
+ cout << " unmet - Show unmet dependencies" << endl;
+ cout << " check - Check the cache a bit" << endl;
+ cout << " search - Search the package list for a regex pattern" << endl;
+ cout << " show - Show a readable record for the package" << endl;
+ cout << endl;
+ cout << "Options:" << endl;
+ cout << " -h This help text." << endl;
+ cout << " -p=? The package cache. [" << _config->FindFile("Dir::Cache::pkgcache") << ']' << endl;
+ cout << " -s=? The source cache. [" << _config->FindFile("Dir::Cache::srcpkgcache") << ']' << endl;
+ cout << " -q Disable progress indicator." << endl;
+ cout << " -i Show only important deps for the unmet command." << endl;
+ cout << " -c=? Read this configuration file" << endl;
+ cout << " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp" << endl;
+ cout << "See the apt-cache(8) and apt.conf(5) manual pages for more information." << endl;
+ return 100;
+}
+ /*}}}*/
+// CacheInitialize - Initialize things for apt-cache /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void CacheInitialize()
+{
+ _config->Set("quiet",0);
+ _config->Set("help",false);
+}
+ /*}}}*/
+
+int main(int argc,const char *argv[])
+{
+ CommandLine::Args Args[] = {
+ {'h',"help","help",0},
+ {'v',"version","version",0},
+ {'p',"pkg-cache","Dir::Cache::pkgcache",CommandLine::HasArg},
+ {'s',"src-cache","Dir::Cache::srcpkgcache",CommandLine::HasArg},
+ {'q',"quiet","quiet",CommandLine::IntLevel},
+ {'i',"important","APT::Cache::Important",0},
+ {'f',"full","APT::Cache::ShowFull",0},
+ {0,"names-only","APT::Cache::NamesOnly",0},
+ {'c',"config-file",0,CommandLine::ConfigFile},
+ {'o',"option",0,CommandLine::ArbItem},
+ {0,0,0,0}};
+ CommandLine::Dispatch CmdsA[] = {{"help",&ShowHelp},
+ {"add",&DoAdd},
+ {"gencaches",&GenCaches},
+ {0,0}};
+ CommandLine::Dispatch CmdsB[] = {{"showpkg",&DumpPackage},
+ {"stats",&Stats},
+ {"dump",&Dump},
+ {"dumpavail",&DumpAvail},
+ {"unmet",&UnMet},
+ {"check",&Check},
+ {"search",&Search},
+ {"show",&ShowPackage},
+ {0,0}};
+
+ CacheInitialize();
+
+ // Parse the command line and initialize the package library
+ CommandLine CmdL(Args,_config);
+ if (pkgInitialize(*_config) == false ||
+ CmdL.Parse(argc,argv) == false)
+ {
+ _error->DumpErrors();
+ return 100;
+ }
+
+ // See if the help should be shown
+ if (_config->FindB("help") == true ||
+ CmdL.FileSize() == 0)
+ return ShowHelp(CmdL);
+
+ // Deal with stdout not being a tty
+ if (ttyname(STDOUT_FILENO) == 0 && _config->FindI("quiet",0) < 1)
+ _config->Set("quiet","1");
+
+ if (CmdL.DispatchArg(CmdsA,false) == false && _error->PendingError() == false)
+ {
+ // Open the cache file
+ pkgSourceList List;
+ List.ReadMainList();
+
+ // Generate it and map it
+ OpProgress Prog;
+ MMap *Map = pkgMakeStatusCacheMem(List,Prog);
+ if (_error->PendingError() == false)