X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/eba2b51d9eb9d0ed6a7ffd540c076870105aecc0..a947ddf372849cb7ba989c16661974c2333e3257:/cmdline/apt-cache.cc diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index ed3c31531..0014563b8 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: apt-cache.cc,v 1.63 2003/04/27 02:47:44 doogie Exp $ +// $Id: apt-cache.cc,v 1.72 2004/04/30 04:34:03 mdz Exp $ /* ###################################################################### apt-cache - Manages the cache files @@ -37,6 +37,8 @@ #include #include #include + +#include /*}}}*/ using namespace std; @@ -227,7 +229,7 @@ bool DumpPackage(CommandLine &CmdL) bool Stats(CommandLine &Cmd) { pkgCache &Cache = *GCache; - cout << _("Total Package Names : ") << Cache.Head().PackageCount << " (" << + cout << _("Total package names : ") << Cache.Head().PackageCount << " (" << SizeToStr(Cache.Head().PackageCount*Cache.Head().PackageSz) << ')' << endl; int Normal = 0; @@ -267,20 +269,20 @@ bool Stats(CommandLine &Cmd) continue; } } - cout << _(" Normal Packages: ") << Normal << endl; - cout << _(" Pure Virtual Packages: ") << Virtual << endl; - cout << _(" Single Virtual Packages: ") << DVirt << endl; - cout << _(" Mixed Virtual Packages: ") << NVirt << endl; + cout << _(" Normal packages: ") << Normal << endl; + cout << _(" Pure virtual packages: ") << Virtual << endl; + cout << _(" Single virtual packages: ") << DVirt << endl; + cout << _(" Mixed virtual packages: ") << NVirt << endl; cout << _(" Missing: ") << Missing << endl; - cout << _("Total Distinct Versions: ") << Cache.Head().VersionCount << " (" << + cout << _("Total distinct versions: ") << Cache.Head().VersionCount << " (" << SizeToStr(Cache.Head().VersionCount*Cache.Head().VersionSz) << ')' << endl; - cout << _("Total Dependencies: ") << Cache.Head().DependsCount << " (" << + cout << _("Total dependencies: ") << Cache.Head().DependsCount << " (" << SizeToStr(Cache.Head().DependsCount*Cache.Head().DependencySz) << ')' << endl; - cout << _("Total Ver/File relations: ") << Cache.Head().VerFileCount << " (" << + cout << _("Total ver/file relations: ") << Cache.Head().VerFileCount << " (" << SizeToStr(Cache.Head().VerFileCount*Cache.Head().VerFileSz) << ')' << endl; - cout << _("Total Provides Mappings: ") << Cache.Head().ProvidesCount << " (" << + cout << _("Total Provides mappings: ") << Cache.Head().ProvidesCount << " (" << SizeToStr(Cache.Head().ProvidesCount*Cache.Head().ProvidesSz) << ')' << endl; // String list stats @@ -292,7 +294,7 @@ bool Stats(CommandLine &Cmd) Count++; Size += strlen(Cache.StrP + I->String) + 1; } - cout << _("Total Globbed Strings: ") << Count << " (" << SizeToStr(Size) << ')' << endl; + cout << _("Total globbed strings: ") << Count << " (" << SizeToStr(Size) << ')' << endl; unsigned long DepVerSize = 0; for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) @@ -306,12 +308,12 @@ bool Stats(CommandLine &Cmd) } } } - cout << _("Total Dependency Version space: ") << SizeToStr(DepVerSize) << endl; + cout << _("Total dependency version space: ") << SizeToStr(DepVerSize) << endl; unsigned long Slack = 0; for (int I = 0; I != 7; I++) Slack += Cache.Head().Pools[I].ItemSize*Cache.Head().Pools[I].Count; - cout << _("Total Slack space: ") << SizeToStr(Slack) << endl; + cout << _("Total slack space: ") << SizeToStr(Slack) << endl; unsigned long Total = 0; Total = Slack + Size + Cache.Head().DependsCount*Cache.Head().DependencySz + @@ -319,7 +321,7 @@ bool Stats(CommandLine &Cmd) Cache.Head().PackageCount*Cache.Head().PackageSz + Cache.Head().VerFileCount*Cache.Head().VerFileSz + Cache.Head().ProvidesCount*Cache.Head().ProvidesSz; - cout << _("Total Space Accounted for: ") << SizeToStr(Total) << endl; + cout << _("Total space accounted for: ") << SizeToStr(Total) << endl; return true; } @@ -1195,7 +1197,7 @@ bool DisplayRecord(pkgCache::VerIterator V) Buffer[V.FileList()->Size] = '\n'; if (PkgF.Seek(V.FileList()->Offset) == false || PkgF.Read(Buffer,V.FileList()->Size) == false || - write(STDOUT_FILENO,Buffer,V.FileList()->Size+1) != V.FileList()->Size+1) + fwrite(Buffer,1,V.FileList()->Size+1,stdout) < (size_t)(V.FileList()->Size+1)) { delete [] Buffer; return false; @@ -1344,6 +1346,8 @@ bool ShowPackage(CommandLine &CmdL) { pkgCache &Cache = *GCache; pkgDepCache::Policy Plcy; + + unsigned found = 0; for (const char **I = CmdL.FileList + 1; *I != 0; I++) { @@ -1354,6 +1358,8 @@ bool ShowPackage(CommandLine &CmdL) continue; } + ++found; + // Find the proper version to use. if (_config->FindB("APT::Cache::AllVersions","true") == true) { @@ -1373,7 +1379,10 @@ bool ShowPackage(CommandLine &CmdL) return false; } } - return true; + + if (found > 0) + return true; + return _error->Error(_("No packages found")); } /*}}}*/ // ShowPkgNames - Show package names /*{{{*/ @@ -1450,7 +1459,7 @@ bool Policy(CommandLine &CmdL) // Print out all of the package files if (CmdL.FileList[1] == 0) { - cout << _("Package Files:") << endl; + cout << _("Package files:") << endl; for (pkgCache::PkgFileIterator F = Cache.FileBegin(); F.end() == false; F++) { // Locate the associated index files so we can derive a description @@ -1470,7 +1479,7 @@ bool Policy(CommandLine &CmdL) } // Show any packages have explicit pins - cout << _("Pinned Packages:") << endl; + cout << _("Pinned packages:") << endl; pkgCache::PkgIterator I = Cache.PkgBegin(); for (;I.end() != true; I++) { @@ -1520,7 +1529,7 @@ bool Policy(CommandLine &CmdL) // Pinned version if (Plcy.GetPriority(Pkg) != 0) { - cout << _(" Package Pin: "); + cout << _(" Package pin: "); V = Plcy.GetMatch(Pkg); if (V.end() == true) cout << _("(not found)") << endl; @@ -1529,7 +1538,7 @@ bool Policy(CommandLine &CmdL) } // Show the priority tables - cout << _(" Version Table:") << endl; + cout << _(" Version table:") << endl; for (V = Pkg.VersionList(); V.end() == false; V++) { if (Pkg.CurrentVer() == V) @@ -1552,6 +1561,74 @@ bool Policy(CommandLine &CmdL) return true; } + /*}}}*/ +// Madison - Look a bit like katie's madison /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool Madison(CommandLine &CmdL) +{ + if (SrcList == 0) + return _error->Error("Generate must be enabled for this function"); + + SrcList->ReadMainList(); + + pkgCache &Cache = *GCache; + + // Create the text record parsers + pkgSrcRecords SrcRecs(*SrcList); + if (_error->PendingError() == true) + return false; + + for (const char **I = CmdL.FileList + 1; *I != 0; I++) + { + pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); + + if (Pkg.end() == false) + { + for (pkgCache::VerIterator V = Pkg.VersionList(); V.end() == false; V++) + { + for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; VF++) + { +// This might be nice, but wouldn't uniquely identify the source -mdz +// if (VF.File().Archive() != 0) +// { +// cout << setw(10) << Pkg.Name() << " | " << setw(10) << V.VerStr() << " | " +// << VF.File().Archive() << endl; +// } + + // Locate the associated index files so we can derive a description + for (pkgSourceList::const_iterator S = SrcList->begin(); S != SrcList->end(); S++) + { + vector *Indexes = (*S)->GetIndexFiles(); + for (vector::const_iterator IF = Indexes->begin(); + IF != Indexes->end(); IF++) + { + if ((*IF)->FindInCache(*(VF.File().Cache())) == VF.File()) + { + cout << setw(10) << Pkg.Name() << " | " << setw(10) << V.VerStr() << " | " + << (*IF)->Describe(true) << endl; + } + } + } + } + } + } + + + SrcRecs.Restart(); + pkgSrcRecords::Parser *SrcParser; + while ((SrcParser = SrcRecs.Find(*I,false)) != 0) + { + // Maybe support Release info here too eventually + cout << setw(10) << SrcParser->Package() << " | " + << setw(10) << SrcParser->Version() << " | " + << SrcParser->Index().Describe(true) << endl; + } + } + + return true; +} + /*}}}*/ // GenCaches - Call the main cache generator /*{{{*/ // --------------------------------------------------------------------- @@ -1574,9 +1651,12 @@ bool ShowHelp(CommandLine &Cmd) ioprintf(cout,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE,VERSION, COMMON_OS,COMMON_CPU,__DATE__,__TIME__); + if (_config->FindB("version") == true) + return true; + cout << _("Usage: apt-cache [options] command\n" - " apt-cache [options] add file1 [file1 ...]\n" + " apt-cache [options] add file1 [file2 ...]\n" " apt-cache [options] showpkg pkg1 [pkg2 ...]\n" " apt-cache [options] showsrc pkg1 [pkg2 ...]\n" "\n" @@ -1608,7 +1688,7 @@ bool ShowHelp(CommandLine &Cmd) " -q Disable progress indicator.\n" " -i Show only important deps for the unmet command.\n" " -c=? Read this configuration file\n" - " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n" + " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n" "See the apt-cache(8) and apt.conf(5) manual pages for more information.\n"); return true; } @@ -1635,12 +1715,12 @@ int main(int argc,const char *argv[]) {'f',"full","APT::Cache::ShowFull",0}, {'g',"generate","APT::Cache::Generate",0}, {'a',"all-versions","APT::Cache::AllVersions",0}, - {0,"names-only","APT::Cache::NamesOnly",0}, - {'n',"all-names","APT::Cache::AllNames",0}, + {'n',"names-only","APT::Cache::NamesOnly",0}, + {0,"all-names","APT::Cache::AllNames",0}, {0,"recurse","APT::Cache::RecurseDepends",0}, {'c',"config-file",0,CommandLine::ConfigFile}, {'o',"option",0,CommandLine::ArbItem}, - {'n',"installed","APT::Cache::Installed",0}, + {0,"installed","APT::Cache::Installed",0}, {0,0,0,0}}; CommandLine::Dispatch CmdsA[] = {{"help",&ShowHelp}, {"add",&DoAdd}, @@ -1660,6 +1740,7 @@ int main(int argc,const char *argv[]) {"show",&ShowPackage}, {"pkgnames",&ShowPkgNames}, {"policy",&Policy}, + {"madison",&Madison}, {0,0}}; CacheInitialize(); @@ -1687,7 +1768,7 @@ int main(int argc,const char *argv[]) } // Deal with stdout not being a tty - if (ttyname(STDOUT_FILENO) == 0 && _config->FindI("quiet",0) < 1) + if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1) _config->Set("quiet","1"); if (CmdL.DispatchArg(CmdsA,false) == false && _error->PendingError() == false)