move ShowPkg() from apt-get to the PkgIterator and rename it to FullName()
[ntk/apt.git] / cmdline / apt-cache.cc
index f10ea48..355e9ae 100644 (file)
@@ -102,15 +102,13 @@ bool UnMet(CommandLine &CmdL)
            if (End->Type != pkgCache::Dep::PreDepends &&
                End->Type != pkgCache::Dep::Depends && 
                End->Type != pkgCache::Dep::Suggests &&
-               End->Type != pkgCache::Dep::Recommends &&
-               End->Type != pkgCache::Dep::DpkgBreaks)
+               End->Type != pkgCache::Dep::Recommends)
               continue;
 
            // Important deps only
            if (Important == true)
               if (End->Type != pkgCache::Dep::PreDepends &&
-                  End->Type != pkgCache::Dep::Depends &&
-                  End->Type != pkgCache::Dep::DpkgBreaks)
+                  End->Type != pkgCache::Dep::Depends)
                  continue;
            
            // Verify the or group
@@ -141,7 +139,7 @@ bool UnMet(CommandLine &CmdL)
            // Oops, it failed..
            if (Header == false)
               ioprintf(cout,_("Package %s version %s has an unmet dep:\n"),
-                       P.Name(),V.VerStr());
+                       P.FullName(true).c_str(),V.VerStr());
            Header = true;
            
            // Print out the dep type
@@ -151,7 +149,7 @@ bool UnMet(CommandLine &CmdL)
            Start = RealStart;
            do
            {
-              cout << Start.TargetPkg().Name();
+              cout << Start.TargetPkg().FullName(true);
               if (Start.TargetVer() != 0)
                  cout << " (" << Start.CompType() << " " << Start.TargetVer() <<
                  ")";
@@ -184,7 +182,7 @@ bool DumpPackage(CommandLine &CmdL)
         continue;
       }
 
-      cout << "Package: " << Pkg.Name() << endl;
+      cout << "Package: " << Pkg.FullName(true) << endl;
       cout << "Versions: " << endl;
       for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++)
       {
@@ -206,7 +204,7 @@ bool DumpPackage(CommandLine &CmdL)
       cout << "Reverse Depends: " << endl;
       for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() != true; D++)
       {
-        cout << "  " << D.ParentPkg().Name() << ',' << D.TargetPkg().Name();
+        cout << "  " << D.ParentPkg().FullName(true) << ',' << D.TargetPkg().FullName(true);
         if (D->Version != 0)
            cout << ' ' << DeNull(D.TargetVer()) << endl;
         else
@@ -218,7 +216,7 @@ bool DumpPackage(CommandLine &CmdL)
       {
         cout << Cur.VerStr() << " - ";
         for (pkgCache::DepIterator Dep = Cur.DependsList(); Dep.end() != true; Dep++)
-           cout << Dep.TargetPkg().Name() << " (" << (int)Dep->CompareOp << " " << DeNull(Dep.TargetVer()) << ") ";
+           cout << Dep.TargetPkg().FullName(true) << " (" << (int)Dep->CompareOp << " " << DeNull(Dep.TargetVer()) << ") ";
         cout << endl;
       }      
 
@@ -227,12 +225,12 @@ bool DumpPackage(CommandLine &CmdL)
       {
         cout << Cur.VerStr() << " - ";
         for (pkgCache::PrvIterator Prv = Cur.ProvidesList(); Prv.end() != true; Prv++)
-           cout << Prv.ParentPkg().Name() << " ";
+           cout << Prv.ParentPkg().FullName(true) << " ";
         cout << endl;
       }
       cout << "Reverse Provides: " << endl;
       for (pkgCache::PrvIterator Prv = Pkg.ProvidesList(); Prv.end() != true; Prv++)
-        cout << Prv.OwnerPkg().Name() << " " << Prv.OwnerVer().VerStr() << endl;            
+        cout << Prv.OwnerPkg().FullName(true) << " " << Prv.OwnerVer().VerStr() << endl;
    }
 
    return true;
@@ -355,13 +353,13 @@ bool Dump(CommandLine &Cmd)
    
    for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
    {
-      cout << "Package: " << P.Name() << endl;
+      cout << "Package: " << P.FullName(true) << endl;
       for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++)
       {
         cout << " Version: " << V.VerStr() << endl;
         cout << "     File: " << V.FileList().File().FileName() << endl;
         for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++)
-           cout << "  Depends: " << D.TargetPkg().Name() << ' ' << 
+           cout << "  Depends: " << D.TargetPkg().FullName(true) << ' ' << 
                             DeNull(D.TargetVer()) << endl;
         for (pkgCache::DescIterator D = V.DescriptionList(); D.end() == false; D++)
         {
@@ -401,7 +399,7 @@ bool DumpAvail(CommandLine &Cmd)
    pkgCache &Cache = *GCache;
 
    pkgPolicy Plcy(&Cache);
-   if (ReadPinFile(Plcy) == false)
+   if (ReadPinFile(Plcy) == false || ReadPinDir(Plcy) == false)
       return false;
    
    unsigned long Count = Cache.HeaderP->PackageCount+1;
@@ -557,6 +555,7 @@ bool Depends(CommandLine &CmdL)
    
    bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false);
    bool Installed = _config->FindB("APT::Cache::Installed",false);
+   bool Important = _config->FindB("APT::Cache::Important",false);
    bool DidSomething;
    do
    {
@@ -571,15 +570,20 @@ bool Depends(CommandLine &CmdL)
         pkgCache::VerIterator Ver = Pkg.VersionList();
         if (Ver.end() == true)
         {
-           cout << '<' << Pkg.Name() << '>' << endl;
+           cout << '<' << Pkg.FullName(true) << '>' << endl;
            continue;
         }
         
-        cout << Pkg.Name() << endl;
+        cout << Pkg.FullName(true) << endl;
         
         for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
         {
-
+           // Important deps only
+           if (Important == true)
+              if (D->Type != pkgCache::Dep::PreDepends &&
+                  D->Type != pkgCache::Dep::Depends)
+                 continue;
+                 
            pkgCache::PkgIterator Trg = D.TargetPkg();
 
            if((Installed && Trg->CurrentVer != 0) || !Installed)
@@ -592,9 +596,9 @@ bool Depends(CommandLine &CmdL)
            
                // Show the package
                if (Trg->VersionList == 0)
-                 cout << D.DepType() << ": <" << Trg.Name() << ">" << endl;
+                 cout << D.DepType() << ": <" << Trg.FullName(true) << ">" << endl;
                else
-                 cout << D.DepType() << ": " << Trg.Name() << endl;
+                 cout << D.DepType() << ": " << Trg.FullName(true) << endl;
            
                if (Recurse == true)
                  Colours[D.TargetPkg()->ID]++;
@@ -610,7 +614,7 @@ bool Depends(CommandLine &CmdL)
               if (V != Cache.VerP + V.ParentPkg()->VersionList ||
                   V->ParentPkg == D->Package)
                  continue;
-              cout << "    " << V.ParentPkg().Name() << endl;
+              cout << "    " << V.ParentPkg().FullName(true) << endl;
               
               if (Recurse == true)
                  Colours[D.ParentPkg()->ID]++;
@@ -622,7 +626,7 @@ bool Depends(CommandLine &CmdL)
    
    return true;
 }
-
+                                                                       /*}}}*/
 // RDepends - Print out a reverse dependency tree - mbc                        /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -659,11 +663,11 @@ bool RDepends(CommandLine &CmdL)
         pkgCache::VerIterator Ver = Pkg.VersionList();
         if (Ver.end() == true)
         {
-           cout << '<' << Pkg.Name() << '>' << endl;
+           cout << '<' << Pkg.FullName(true) << '>' << endl;
            continue;
         }
         
-        cout << Pkg.Name() << endl;
+        cout << Pkg.FullName(true) << endl;
         
         cout << "Reverse Depends:" << endl;
         for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false; D++)
@@ -680,9 +684,9 @@ bool RDepends(CommandLine &CmdL)
                  cout << "  ";
 
                if (Trg->VersionList == 0)
-                 cout << D.DepType() << ": <" << Trg.Name() << ">" << endl;
+                 cout << D.DepType() << ": <" << Trg.FullName(true) << ">" << endl;
                else
-                 cout << Trg.Name() << endl;
+                 cout << Trg.FullName(true) << endl;
 
                if (Recurse == true)
                  Colours[D.ParentPkg()->ID]++;
@@ -698,7 +702,7 @@ bool RDepends(CommandLine &CmdL)
               if (V != Cache.VerP + V.ParentPkg()->VersionList ||
                   V->ParentPkg == D->Package)
                  continue;
-              cout << "    " << V.ParentPkg().Name() << endl;
+              cout << "    " << V.ParentPkg().FullName(true) << endl;
               
               if (Recurse == true)
                  Colours[D.ParentPkg()->ID]++;
@@ -710,10 +714,7 @@ bool RDepends(CommandLine &CmdL)
    
    return true;
 }
-
                                                                        /*}}}*/
-
-
 // xvcg - Generate a graph for xvcg                                    /*{{{*/
 // ---------------------------------------------------------------------
 // Code contributed from Junichi Uekawa <dancer@debian.org> on 20 June 2002.
@@ -862,7 +863,7 @@ bool XVcg(CommandLine &CmdL)
            // Only graph critical deps     
            if (D.IsCritical() == true)
            {
-              printf ("edge: { sourcename: \"%s\" targetname: \"%s\" class: 2 ",Pkg.Name(), D.TargetPkg().Name() );
+              printf ("edge: { sourcename: \"%s\" targetname: \"%s\" class: 2 ",Pkg.FullName(true).c_str(), D.TargetPkg().FullName(true).c_str() );
               
               // Colour the node for recursion
               if (Show[D.TargetPkg()->ID] <= DoneNR)
@@ -921,20 +922,22 @@ bool XVcg(CommandLine &CmdL)
         continue;
 
       if (Show[Pkg->ID] == DoneNR)
-        printf("node: { title: \"%s\" label: \"%s\" color: orange shape: %s }\n", Pkg.Name(), Pkg.Name(),
+        printf("node: { title: \"%s\" label: \"%s\" color: orange shape: %s }\n", Pkg.FullName(true).c_str(), Pkg.FullName(true).c_str(),
                Shapes[ShapeMap[Pkg->ID]]);
       else
-       printf("node: { title: \"%s\" label: \"%s\" shape: %s }\n", Pkg.Name(), Pkg.Name(), 
+       printf("node: { title: \"%s\" label: \"%s\" shape: %s }\n", Pkg.FullName(true).c_str(), Pkg.FullName(true).c_str(),
                Shapes[ShapeMap[Pkg->ID]]);
       
    }
-   
+
+   delete[] Show;
+   delete[] Flags;
+   delete[] ShapeMap;
+
    printf("}\n");
    return true;
 }
                                                                        /*}}}*/
-
-
 // Dotty - Generate a graph for Dotty                                  /*{{{*/
 // ---------------------------------------------------------------------
 /* Dotty is the graphvis program for generating graphs. It is a fairly
@@ -1081,7 +1084,7 @@ bool Dotty(CommandLine &CmdL)
            // Only graph critical deps     
            if (D.IsCritical() == true)
            {
-              printf("\"%s\" -> \"%s\"",Pkg.Name(),D.TargetPkg().Name());
+              printf("\"%s\" -> \"%s\"",Pkg.FullName(true).c_str(),D.TargetPkg().FullName(true).c_str());
               
               // Colour the node for recursion
               if (Show[D.TargetPkg()->ID] <= DoneNR)
@@ -1135,10 +1138,10 @@ bool Dotty(CommandLine &CmdL)
       
       // Orange box for early recursion stoppage
       if (Show[Pkg->ID] == DoneNR)
-        printf("\"%s\" [color=orange,shape=%s];\n",Pkg.Name(),
+        printf("\"%s\" [color=orange,shape=%s];\n",Pkg.FullName(true).c_str(),
                Shapes[ShapeMap[Pkg->ID]]);
       else
-        printf("\"%s\" [shape=%s];\n",Pkg.Name(),
+        printf("\"%s\" [shape=%s];\n",Pkg.FullName(true).c_str(),
                Shapes[ShapeMap[Pkg->ID]]);
    }
    
@@ -1270,15 +1273,16 @@ bool DisplayRecord(pkgCache::VerIterator V)
    return true;
 }
                                                                        /*}}}*/
-// Search - Perform a search                                           /*{{{*/
-// ---------------------------------------------------------------------
-/* This searches the package names and pacakge descriptions for a pattern */
+
 struct ExDescFile
 {
    pkgCache::DescFile *Df;
    bool NameMatch;
 };
 
+// Search - Perform a search                                           /*{{{*/
+// ---------------------------------------------------------------------
+/* This searches the package names and package descriptions for a pattern */
 bool Search(CommandLine &CmdL)
 {
    pkgCache &Cache = *GCache;
@@ -1413,11 +1417,15 @@ bool ShowPackage(CommandLine &CmdL)
    
    for (const char **I = CmdL.FileList + 1; *I != 0; I++)
    {
+      // FIXME: Handle the case in which pkgname name:arch is not found
       pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
       if (Pkg.end() == true)
       {
-        _error->Warning(_("Unable to locate package %s"),*I);
-        continue;
+        Pkg = Cache.FindPkg(*I, "any");
+        if (Pkg.end() == true) {
+               _error->Warning(_("Unable to locate package %s"),*I);
+               continue;
+        }
       }
 
       ++found;
@@ -1453,16 +1461,17 @@ bool ShowPackage(CommandLine &CmdL)
 bool ShowPkgNames(CommandLine &CmdL)
 {
    pkgCache &Cache = *GCache;
-   pkgCache::PkgIterator I = Cache.PkgBegin();
-   bool All = _config->FindB("APT::Cache::AllNames","false");
-   
+   pkgCache::GrpIterator I = Cache.GrpBegin();
+   bool const All = _config->FindB("APT::Cache::AllNames","false");
+
    if (CmdL.FileList[1] != 0)
    {
       for (;I.end() != true; I++)
       {
-        if (All == false && I->VersionList == 0)
+        if (All == false && I->FirstPackage == 0)
+           continue;
+        if (I.FindPkg("any")->VersionList == 0)
            continue;
-        
         if (strncmp(I.Name(),CmdL.FileList[1],strlen(CmdL.FileList[1])) == 0)
            cout << I.Name() << endl;
       }
@@ -1473,7 +1482,9 @@ bool ShowPkgNames(CommandLine &CmdL)
    // Show all pkgs
    for (;I.end() != true; I++)
    {
-      if (All == false && I->VersionList == 0)
+      if (All == false && I->FirstPackage == 0)
+        continue;
+      if (I.FindPkg("any")->VersionList == 0)
         continue;
       cout << I.Name() << endl;
    }
@@ -1515,7 +1526,7 @@ bool Policy(CommandLine &CmdL)
    
    pkgCache &Cache = *GCache;
    pkgPolicy Plcy(&Cache);
-   if (ReadPinFile(Plcy) == false)
+   if (ReadPinFile(Plcy) == false || ReadPinDir(Plcy) == false)
       return false;
    
    // Print out all of the package files
@@ -1529,7 +1540,8 @@ bool Policy(CommandLine &CmdL)
         if (SrcList->FindIndex(F,Indx) == false &&
             _system->FindIndex(F,Indx) == false)
            return _error->Error(_("Cache is out of sync, can't x-ref a package file"));
-        printf(_("%4i %s\n"),
+        
+        printf("%4i %s\n",
                Plcy.GetPriority(F),Indx->Describe(true).c_str());
         
         // Print the reference information for the package
@@ -1549,7 +1561,7 @@ bool Policy(CommandLine &CmdL)
            continue;
 
         // Print the package name and the version we are forcing to
-        cout << "     " << I.Name() << " -> ";
+        cout << "     " << I.FullName(true) << " -> ";
         
         pkgCache::VerIterator V = Plcy.GetMatch(I);
         if (V.end() == true)
@@ -1560,19 +1572,26 @@ bool Policy(CommandLine &CmdL)
       
       return true;
    }
-   
+
+   string const myArch = _config->Find("APT::Architecture");
+
    // Print out detailed information for each package
    for (const char **I = CmdL.FileList + 1; *I != 0; I++)
    {
-      pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
+      pkgCache::GrpIterator Grp = Cache.FindGrp(*I);
+      pkgCache::PkgIterator Pkg = Grp.FindPkg("any");
       if (Pkg.end() == true)
       {
         _error->Warning(_("Unable to locate package %s"),*I);
         continue;
       }
-      
-      cout << Pkg.Name() << ":" << endl;
-      
+
+      for (; Pkg.end() != true; Pkg = Grp.NextPkg(Pkg)) {
+      if (strcmp(Pkg.Arch(),"all") == 0)
+        continue;
+
+      cout << Pkg.FullName(true) << ":" << endl;
+
       // Installed version
       cout << _("  Installed: ");
       if (Pkg->CurrentVer == 0)
@@ -1615,10 +1634,11 @@ bool Policy(CommandLine &CmdL)
            if (SrcList->FindIndex(VF.File(),Indx) == false &&
                _system->FindIndex(VF.File(),Indx) == false)
               return _error->Error(_("Cache is out of sync, can't x-ref a package file"));
-           printf(_("       %4i %s\n"),Plcy.GetPriority(VF.File()),
+           printf("       %4i %s\n",Plcy.GetPriority(VF.File()),
                   Indx->Describe(true).c_str());
-        }       
-      }      
+        }
+      }
+      }
    }
    
    return true;
@@ -1668,7 +1688,7 @@ bool Madison(CommandLine &CmdL)
                     {
                          if ((*IF)->FindInCache(*(VF.File().Cache())) == VF.File())
                          {
-                                   cout << setw(10) << Pkg.Name() << " | " << setw(10) << V.VerStr() << " | "
+                                   cout << setw(10) << Pkg.FullName(true) << " | " << setw(10) << V.VerStr() << " | "
                                         << (*IF)->Describe(true) << endl;
                          }
                     }
@@ -1691,7 +1711,6 @@ bool Madison(CommandLine &CmdL)
 
    return true;
 }
-
                                                                        /*}}}*/
 // GenCaches - Call the main cache generator                           /*{{{*/
 // ---------------------------------------------------------------------
@@ -1739,8 +1758,8 @@ bool ShowHelp(CommandLine &Cmd)
       "   show - Show a readable record for the package\n"
       "   depends - Show raw dependency information for a package\n"
       "   rdepends - Show reverse dependency information for a package\n"
-      "   pkgnames - List the names of all packages\n"
-      "   dotty - Generate package graphs for GraphVis\n"
+      "   pkgnames - List the names of all packages in the system\n"
+      "   dotty - Generate package graphs for GraphViz\n"
       "   xvcg - Generate package graphs for xvcg\n"
       "   policy - Show policy settings\n"
       "\n"
@@ -1765,8 +1784,7 @@ void CacheInitialize()
    _config->Set("help",false);
 }
                                                                        /*}}}*/
-
-int main(int argc,const char *argv[])
+int main(int argc,const char *argv[])                                  /*{{{*/
 {
    CommandLine::Args Args[] = {
       {'h',"help","help",0},
@@ -1873,3 +1891,4 @@ int main(int argc,const char *argv[])
           
    return 0;
 }
+                                                                       /*}}}*/