[PATCH] Update of "size" column patch for setup (Was Re: Is setup-2.506 ready to release?)

Igor Pechtchanski pechtcha@cs.nyu.edu
Fri Aug 19 18:04:00 GMT 2005


On Fri, 19 Aug 2005, Igor Pechtchanski wrote:

> On Fri, 19 Aug 2005, Brian Dessent wrote:
>
> > WRT to your patch that adds the size column, I would like to apply it
> > but I was hoping for a version that used MB instead of bytes, so that
> > the column is a little easier to read.  If you already posted that one
> > then please forgive me as I must have missed it.
>
> No, it's my fault -- I've been meaning to get back to it and fix it, but
> got sidetracked (though I was planning to use the "...k" formatting).
> I'll see what I can do in the next week or so.  FWIW, I'm not going to be
> particularly disappointed if it doesn't appear in the next release...

Ok, attached is a quick update to that patch -- please let me know if it
needs more work.  ChangeLog is at the end of this message.

> > Also, that change that makes it try bash instead of sh for scripts
> > should go in if we're about to release.

FWIW, I also have another patch, one that propagates the exit code of
postinstall scripts to setup.  It doesn't yet do anything about the exit
code, though.  I'll send that one out in a separate message.
	Igor
==============================================================================
ChangeLog:
2005-08-19  Igor Pechtchanski  <pechtcha@cs.nyu.edu>

	* PickView.h (PickView::size_col): New instance variable.
	* PickView.cc (pkg_headers, cat_headers): Add size column.
	(PickView::set_headers): Initialize size_col.
	(PickView::init_headers): Include width of size column.
	* PickPackageLine.cc (PickPackageLine::paint): Handle size_col.
	* String++.cc (format_1000s): New function.
	* String++.h (format_1000s): Declare new function.

-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

If there's any real truth it's that the entire multidimensional infinity
of the Universe is almost certainly being run by a bunch of maniacs. /DA
-------------- next part --------------
Index: PickPackageLine.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/PickPackageLine.cc,v
retrieving revision 2.16
diff -u -p -r2.16 PickPackageLine.cc
--- PickPackageLine.cc	21 May 2005 23:04:02 -0000	2.16
+++ PickPackageLine.cc	19 Aug 2005 17:52:10 -0000
@@ -88,6 +88,28 @@ PickPackageLine::paint (HDC hdc, HRGN un
           TextOut (hdc, x + HMARGIN / 2, y, s.c_str(), s.size());
         }
     }
+  else if (col_num == theView.size_col)
+    {
+      int sz = 0;
+      // Use chosen version or the default
+      packageversion picked = pkg.desired;
+      if (!picked) picked = pkg.trustp(theView.deftrust);
+      // If source is picked, add up the size
+      if (picked.sourcePackage().picked())
+        sz += picked.sourcePackage().source()->size;
+      // If binary or nothing is picked, add up the binary size
+      if (picked.picked() || sz == 0)
+	sz += picked.source()->size;
+      // If no binary, add up the source size
+      if (sz == 0)
+        sz += picked.sourcePackage().source()->size;
+      // If size still 0, size must be unknown
+      s = (sz == 0) ? "?" : format_1000s((sz+1023)/1024) + "k";
+      SIZE tw;
+      GetTextExtentPoint32 (hdc, s.c_str(), s.size(), &tw);
+      int cw = theView.headers[col_num].width - HMARGIN - tw.cx;
+      TextOut (hdc, x + cw + HMARGIN / 2, y, s.c_str(), s.size());
+    }
   else if (col_num == theView.pkg_col)
     {
       s = pkg.name;
Index: PickView.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/PickView.cc,v
retrieving revision 2.24
diff -u -p -r2.24 PickView.cc
--- PickView.cc	21 May 2005 23:04:02 -0000	2.24
+++ PickView.cc	19 Aug 2005 17:52:11 -0000
@@ -34,6 +34,7 @@ static PickView::Header pkg_headers[] = 
   {"Bin?", 0, 0, false},
   {"Src?", 0, 0, false},
   {"Categories", 0, 0, true},
+  {"Size", 0, 0, true},
   {"Package", 0, 0, true},
   {0, 0, 0, false}
 };
@@ -44,6 +45,7 @@ static PickView::Header cat_headers[] = 
   {"New", 0, 0, true},
   {"Bin?", 0, 0, false},
   {"Src?", 0, 0, false},
+  {"Size", 0, 0, true},
   {"Package", 0, 0, true},
   {0, 0, 0, false}
 };
@@ -98,7 +100,8 @@ PickView::set_headers ()
       bintick_col = new_col + 1;
       srctick_col = bintick_col + 1;
       cat_col = srctick_col + 1;
-      pkg_col = cat_col + 1;
+      size_col = cat_col + 1;
+      pkg_col = size_col + 1;
       last_col = pkg_col;
     }
   else if (view_mode == views::Category)
@@ -109,7 +112,8 @@ PickView::set_headers ()
       bintick_col = new_col + 1;
       srctick_col = bintick_col + 1;
       cat_col = 0;
-      pkg_col = srctick_col + 1;
+      size_col = srctick_col + 1;
+      pkg_col = size_col + 1;
       last_col = pkg_col;
     }
   else
@@ -443,9 +447,15 @@ PickView::init_headers (HDC dc)
                     HMARGIN, current_col);
       for (set<packageversion>::iterator i = pkg.versions.begin ();
 	   i != pkg.versions.end (); ++i)
-        if (*i != pkg.installed)
-          note_width (headers, dc, i->Canonical_version (), 
-                      HMARGIN + SPIN_WIDTH, new_col);
+	{
+          if (*i != pkg.installed)
+            note_width (headers, dc, i->Canonical_version (),
+                        HMARGIN + SPIN_WIDTH, new_col);
+	  String z = format_1000s(packageversion(*i).source ()->size);
+	  note_width (headers, dc, z, HMARGIN, size_col);
+	  z = format_1000s(packageversion(i->sourcePackage ()).source ()->size);
+	  note_width (headers, dc, z, HMARGIN, size_col);
+	}
       String s = pkg.name;
       if (pkg.SDesc ().size())
 	s += String (": ") + pkg.SDesc ();
Index: PickView.h
===================================================================
RCS file: /cvs/cygwin-apps/setup/PickView.h,v
retrieving revision 2.14
diff -u -p -r2.14 PickView.h
--- PickView.h	21 May 2005 23:04:02 -0000	2.14
+++ PickView.h	19 Aug 2005 17:52:11 -0000
@@ -66,6 +66,7 @@ public:
   int bintick_col;
   int srctick_col;
   int cat_col;
+  int size_col;
   int pkg_col;
   int last_col;
   int row_height;
Index: String++.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/String++.cc,v
retrieving revision 2.16
diff -u -p -r2.16 String++.cc
--- String++.cc	5 May 2005 22:48:34 -0000	2.16
+++ String++.cc	19 Aug 2005 17:52:11 -0000
@@ -304,3 +304,23 @@ operator << (ostream &os, String const &
   os << theString.c_str();
   return os;
 }
+
+String
+format_1000s(const int num, char sep)
+{
+  int mult = 1;
+  while (mult * 1000 < num)
+    mult *= 1000;
+  ostringstream os;
+  os << ((num / mult) % 1000);
+  for (mult /= 1000; mult > 0; mult /= 1000)
+    {
+      int triplet = (num / mult) % 1000;
+      os << sep;
+      if (triplet < 100) os << '0';
+      if (triplet < 10) os << '0';
+      os << triplet;
+    }
+  return String(os.str());
+}
+
Index: String++.h
===================================================================
RCS file: /cvs/cygwin-apps/setup/String++.h,v
retrieving revision 2.20
diff -u -p -r2.20 String++.h
--- String++.h	5 May 2005 22:48:34 -0000	2.20
+++ String++.h	19 Aug 2005 17:52:11 -0000
@@ -115,4 +115,7 @@ char *new_cstr_char_array (const String 
    bar", "TOSTRING(foo)", to yield "bar". */
 #define TOSTRING(X) __TOSTRING__(X)
 
+String
+format_1000s(const int num, char sep = ',');
+
 #endif /* SETUP_STRING___H */


More information about the Cygwin-apps mailing list