Преглед на файлове

Sort the output of listings
Author: jgg
Date: 1999-07-12 04:39:37 GMT
Sort the output of listings

Arch Librarian преди 22 години
родител
ревизия
1089ca8975
променени са 2 файла, в които са добавени 92 реда и са изтрити 41 реда
  1. 91 41
      cmdline/apt-get.cc
  2. 1 0
      debian/changelog

+ 91 - 41
cmdline/apt-get.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: apt-get.cc,v 1.70 1999/07/10 05:32:26 jgg Exp $
+// $Id: apt-get.cc,v 1.71 1999/07/12 04:39:37 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    apt-get - Cover for dpkg
    apt-get - Cover for dpkg
@@ -61,6 +61,31 @@ ostream c2out;
 ofstream devnull("/dev/null");
 ofstream devnull("/dev/null");
 unsigned int ScreenWidth = 80;
 unsigned int ScreenWidth = 80;
 
 
+// class CacheFile - Cover class for some dependency cache functions	/*{{{*/
+// ---------------------------------------------------------------------
+/* */
+class CacheFile : public pkgCacheFile
+{
+   static pkgCache *SortCache;
+   static int NameComp(const void *a,const void *b);
+   
+   public:
+   pkgCache::Package **List;
+   
+   void Sort();
+   bool CheckDeps(bool AllowBroken = false);
+   bool Open(bool WithLock = true) 
+   {
+      OpTextProgress Prog(*_config);
+      if (pkgCacheFile::Open(Prog,WithLock) == false)
+	 return false;
+      Sort();
+      return true;
+   };
+   CacheFile() : List(0) {};
+};
+									/*}}}*/
+
 // YnPrompt - Yes No Prompt.						/*{{{*/
 // YnPrompt - Yes No Prompt.						/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* Returns true on a Yes.*/
 /* Returns true on a Yes.*/
@@ -129,12 +154,13 @@ bool ShowList(ostream &out,string Title,string List)
 /* This prints out the names of all the packages that are broken along
 /* This prints out the names of all the packages that are broken along
    with the name of each each broken dependency and a quite version 
    with the name of each each broken dependency and a quite version 
    description. */
    description. */
-void ShowBroken(ostream &out,pkgDepCache &Cache)
+void ShowBroken(ostream &out,CacheFile &Cache)
 {
 {
    out << "Sorry, but the following packages have unmet dependencies:" << endl;
    out << "Sorry, but the following packages have unmet dependencies:" << endl;
-   pkgCache::PkgIterator I = Cache.PkgBegin();
-   for (;I.end() != true; I++)
+   for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
    {
    {
+      pkgCache::PkgIterator I(Cache,Cache.List[J]);
+      
       if (Cache[I].InstBroken() == false)
       if (Cache[I].InstBroken() == false)
 	  continue;
 	  continue;
 	  
 	  
@@ -155,7 +181,7 @@ void ShowBroken(ostream &out,pkgDepCache &Cache)
 	 pkgCache::DepIterator End;
 	 pkgCache::DepIterator End;
 	 D.GlobOr(Start,End);
 	 D.GlobOr(Start,End);
 
 
-	 if (Cache.IsImportantDep(End) == false || 
+	 if (Cache->IsImportantDep(End) == false || 
 	     (Cache[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall)
 	     (Cache[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall)
 	    continue;
 	    continue;
 	 
 	 
@@ -203,32 +229,35 @@ void ShowBroken(ostream &out,pkgDepCache &Cache)
 // ShowNew - Show packages to newly install				/*{{{*/
 // ShowNew - Show packages to newly install				/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
-void ShowNew(ostream &out,pkgDepCache &Dep)
+void ShowNew(ostream &out,CacheFile &Cache)
 {
 {
    /* Print out a list of packages that are going to be removed extra
    /* Print out a list of packages that are going to be removed extra
       to what the user asked */
       to what the user asked */
-   pkgCache::PkgIterator I = Dep.PkgBegin();
    string List;
    string List;
-   for (;I.end() != true; I++)
-      if (Dep[I].NewInstall() == true)
+   for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
+   {
+      pkgCache::PkgIterator I(Cache,Cache.List[J]);
+      if (Cache[I].NewInstall() == true)
 	 List += string(I.Name()) + " ";
 	 List += string(I.Name()) + " ";
+   }
+   
    ShowList(out,"The following NEW packages will be installed:",List);
    ShowList(out,"The following NEW packages will be installed:",List);
 }
 }
 									/*}}}*/
 									/*}}}*/
 // ShowDel - Show packages to delete					/*{{{*/
 // ShowDel - Show packages to delete					/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
-void ShowDel(ostream &out,pkgDepCache &Dep)
+void ShowDel(ostream &out,CacheFile &Cache)
 {
 {
    /* Print out a list of packages that are going to be removed extra
    /* Print out a list of packages that are going to be removed extra
       to what the user asked */
       to what the user asked */
-   pkgCache::PkgIterator I = Dep.PkgBegin();
    string List;
    string List;
-   for (;I.end() != true; I++)
+   for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
    {
    {
-      if (Dep[I].Delete() == true)
+      pkgCache::PkgIterator I(Cache,Cache.List[J]);
+      if (Cache[I].Delete() == true)
       {
       {
-	 if ((Dep[I].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge)
+	 if ((Cache[I].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge)
 	    List += string(I.Name()) + "* ";
 	    List += string(I.Name()) + "* ";
 	 else
 	 else
 	    List += string(I.Name()) + " ";
 	    List += string(I.Name()) + " ";
@@ -260,14 +289,15 @@ void ShowKept(ostream &out,pkgDepCache &Dep)
 // ShowUpgraded - Show upgraded packages				/*{{{*/
 // ShowUpgraded - Show upgraded packages				/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
-void ShowUpgraded(ostream &out,pkgDepCache &Dep)
+void ShowUpgraded(ostream &out,CacheFile &Cache)
 {
 {
-   pkgCache::PkgIterator I = Dep.PkgBegin();
    string List;
    string List;
-   for (;I.end() != true; I++)
+   for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
    {
    {
+      pkgCache::PkgIterator I(Cache,Cache.List[J]);
+      
       // Not interesting
       // Not interesting
-      if (Dep[I].Upgrade() == false || Dep[I].NewInstall() == true)
+      if (Cache[I].Upgrade() == false || Cache[I].NewInstall() == true)
 	 continue;
 	 continue;
       
       
       List += string(I.Name()) + " ";
       List += string(I.Name()) + " ";
@@ -278,13 +308,13 @@ void ShowUpgraded(ostream &out,pkgDepCache &Dep)
 // ShowHold - Show held but changed packages				/*{{{*/
 // ShowHold - Show held but changed packages				/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
-bool ShowHold(ostream &out,pkgDepCache &Dep)
+bool ShowHold(ostream &out,CacheFile &Cache)
 {
 {
-   pkgCache::PkgIterator I = Dep.PkgBegin();
    string List;
    string List;
-   for (;I.end() != true; I++)
+   for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
    {
    {
-      if (Dep[I].InstallVer != (pkgCache::Version *)I.CurrentVer() &&
+      pkgCache::PkgIterator I(Cache,Cache.List[J]);
+      if (Cache[I].InstallVer != (pkgCache::Version *)I.CurrentVer() &&
 	  I->SelectedState == pkgCache::State::Hold)
 	  I->SelectedState == pkgCache::State::Hold)
 	 List += string(I.Name()) + " ";
 	 List += string(I.Name()) + " ";
    }
    }
@@ -297,21 +327,21 @@ bool ShowHold(ostream &out,pkgDepCache &Dep)
 /* This prints out a warning message that is not to be ignored. It shows
 /* This prints out a warning message that is not to be ignored. It shows
    all essential packages and their dependents that are to be removed. 
    all essential packages and their dependents that are to be removed. 
    It is insanely risky to remove the dependents of an essential package! */
    It is insanely risky to remove the dependents of an essential package! */
-bool ShowEssential(ostream &out,pkgDepCache &Dep)
+bool ShowEssential(ostream &out,CacheFile &Cache)
 {
 {
-   pkgCache::PkgIterator I = Dep.PkgBegin();
    string List;
    string List;
-   bool *Added = new bool[Dep.HeaderP->PackageCount];
-   for (unsigned int I = 0; I != Dep.HeaderP->PackageCount; I++)
+   bool *Added = new bool[Cache->HeaderP->PackageCount];
+   for (unsigned int I = 0; I != Cache->HeaderP->PackageCount; I++)
       Added[I] = false;
       Added[I] = false;
    
    
-   for (;I.end() != true; I++)
+   for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
    {
    {
+      pkgCache::PkgIterator I(Cache,Cache.List[J]);
       if ((I->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential)
       if ((I->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential)
 	 continue;
 	 continue;
       
       
       // The essential package is being removed
       // The essential package is being removed
-      if (Dep[I].Delete() == true)
+      if (Cache[I].Delete() == true)
       {
       {
 	 if (Added[I->ID] == false)
 	 if (Added[I->ID] == false)
 	 {
 	 {
@@ -332,7 +362,7 @@ bool ShowEssential(ostream &out,pkgDepCache &Dep)
 	    continue;
 	    continue;
 	 
 	 
 	 pkgCache::PkgIterator P = D.SmartTargetPkg();
 	 pkgCache::PkgIterator P = D.SmartTargetPkg();
-	 if (Dep[P].Delete() == true)
+	 if (Cache[P].Delete() == true)
 	 {
 	 {
 	    if (Added[P->ID] == true)
 	    if (Added[P->ID] == true)
 	       continue;
 	       continue;
@@ -377,20 +407,40 @@ void Stats(ostream &out,pkgDepCache &Dep)
 }
 }
 									/*}}}*/
 									/*}}}*/
 
 
-// class CacheFile - Cover class for some dependency cache functions	/*{{{*/
+// CacheFile::NameComp - QSort compare by name				/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
-class CacheFile : public pkgCacheFile
+pkgCache *CacheFile::SortCache = 0;
+int CacheFile::NameComp(const void *a,const void *b)
 {
 {
-   public:
+   if (a == 0 && b == 0)
+      return 0;
+   if (a == 0)
+      return -1;
+   if (b == 0)
+      return 1;
    
    
-   bool CheckDeps(bool AllowBroken = false);
-   bool Open(bool WithLock = true) 
-   {
-      OpTextProgress Prog(*_config); 
-      return pkgCacheFile::Open(Prog,WithLock);
-   };
-};
+   const pkgCache::Package &A = **(pkgCache::Package **)a;
+   const pkgCache::Package &B = **(pkgCache::Package **)b;
+
+   return strcmp(SortCache->StrP + A.Name,SortCache->StrP + B.Name);
+}
+									/*}}}*/
+// CacheFile::Sort - Sort by name					/*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void CacheFile::Sort()
+{
+   delete [] List;
+   List = new pkgCache::Package *[Cache->Head().PackageCount];
+   memset(List,0,sizeof(*List)*Cache->Head().PackageCount);
+   pkgCache::PkgIterator I = Cache->PkgBegin();
+   for (;I.end() != true; I++)
+      List[I->ID] = I;
+
+   SortCache = *this;
+   qsort(List,Cache->Head().PackageCount,sizeof(*List),NameComp);
+}
 									/*}}}*/
 									/*}}}*/
 // CacheFile::Open - Open the cache file				/*{{{*/
 // CacheFile::Open - Open the cache file				/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
@@ -940,9 +990,9 @@ bool DoInstall(CommandLine &CmdL)
    if (Cache->InstCount() != ExpectedInst)
    if (Cache->InstCount() != ExpectedInst)
    {
    {
       string List;
       string List;
-      pkgCache::PkgIterator I = Cache->PkgBegin();
-      for (;I.end() != true; I++)
+      for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
       {
       {
+	 pkgCache::PkgIterator I(Cache,Cache.List[J]);
 	 if ((*Cache)[I].Install() == false)
 	 if ((*Cache)[I].Install() == false)
 	    continue;
 	    continue;
 
 

+ 1 - 0
debian/changelog

@@ -7,6 +7,7 @@ apt (0.3.11.1) unstable; urgency=low
   * Purge support. Closes: #33291, #40694
   * Purge support. Closes: #33291, #40694
   * Error code on failed update. Closes: #41053
   * Error code on failed update. Closes: #41053
   * apt-cdrom adds entries for source directories
   * apt-cdrom adds entries for source directories
+  * Sorts the output of any list. Closes: #41107
   
   
  -- Jason Gunthorpe <jgg@debian.org>  Mon, 28 Jun 1999 21:06:44 -0700
  -- Jason Gunthorpe <jgg@debian.org>  Mon, 28 Jun 1999 21:06:44 -0700