Subject: Bug in SHORTDATE4

From: Chuck Goodhart <[email-masked]>
Date: Mon, 14 Dec 1998 22:25:06 -0800 (PST)

Using an index-format of:
    STATUS MSGNO SHORTDATE3 FROMORTO(33%) SIZE SUBJECT(67%)
in an 80 character wide screen (with a folder with less than 1000
messages) yields field widths of:
    STATUS     =  3
    MSGNO      =  3
    SHORTDATE3 =  8
    FROMORTO   = 17
    SIZE       =  8
    SUBJECT    = 36

However, replacing SHORTDATE3 with SHORTDATE4 i.e.:
    STATUS MSGNO SHORTDATE4 FROMORTO(33%) SIZE SUBJECT(67%)
yields field widths of:
    STATUS     =  3
    MSGNO      =  3
    SHORTDATE4 =  8
    FROMORTO   = 25
    SIZE       =  8
    SUBJECT    = 28

The incorrect percentage width calculation is caused by a minor typo,
which can be fixed by the following patch:
======== begin patch ====================================================
--- pine4.05/pine/mailindx.c.orig	Wed Sep  2 09:22:21 1998
+++ pine4.05/pine/mailindx.c	Sat Dec 12 16:44:32 1998
@@ -2154,7 +2154,7 @@
 	  break;
 
 	case 10:
-	  targetctype = iS3Date;
+	  targetctype = iS4Date;
 	  break;
 
 	case 11:
======== end patch ======================================================

However, the following patch, which replaces the entire switch statement
and explicitly numbered cases with an equivalent table lookup, results in
code which is  less susceptible to this sort of typo:
======== begin patch ====================================================
--- pine4.05/pine/mailindx.c.orig	Wed Sep  2 09:22:21 1998
+++ pine4.05/pine/mailindx.c	Mon Dec 14 08:13:19 1998
@@ -2109,71 +2109,19 @@
      * Calculate the field widths that are basically fixed in width.
      * Do them in this order in case we don't have enough space to go around.
      */
-    for(j = 0; j < 14 && space_left > 0 && some_to_calculate; j++){
-      IndexColType targetctype;
+    for(j = 0; space_left > 0 && some_to_calculate; j++){
+      static IndexColType targetctype[] = {
+	  iMessNo, iStatus, iFStatus, iIStatus, iDate, iSDate, iLDate,
+	  iS1Date, iS2Date, iS3Date, iS4Date, iSize, iDescripSize, iAtt
+      };
 
-      switch(j){
-	case 0:
-	  targetctype = iMessNo;
-	  break;
-
-	case 1:
-	  targetctype = iStatus;
-	  break;
-
-	case 2:
-	  targetctype = iFStatus;
-	  break;
-
-	case 3:
-	  targetctype = iIStatus;
-	  break;
-
-	case 4:
-	  targetctype = iDate;
-	  break;
-
-	case 5:
-	  targetctype = iSDate;
-	  break;
-
-	case 6:
-	  targetctype = iLDate;
-	  break;
-
-	case 7:
-	  targetctype = iS1Date;
-	  break;
-
-	case 8:
-	  targetctype = iS2Date;
-	  break;
-
-	case 9:
-	  targetctype = iS3Date;
-	  break;
-
-	case 10:
-	  targetctype = iS3Date;
-	  break;
-
-	case 11:
-	  targetctype = iSize;
-	  break;
-
-	case 12:
-	  targetctype = iDescripSize;
-	  break;
-
-	case 13:
-	  targetctype = iAtt;
-	  break;
-      }
+      if(j >= sizeof(targetctype)/sizeof(*targetctype))
+	break;
 
       for(cdesc = ps_global->index_disp_format;
 	  cdesc->ctype != iNothing && space_left > 0 && some_to_calculate;
 	  cdesc++)
-	if(cdesc->ctype == targetctype && cdesc->wtype == WeCalculate){
+	if(cdesc->ctype == targetctype[j] && cdesc->wtype == WeCalculate){
 	    some_to_calculate--;
 	    fix = min(cdesc->actual_length - cdesc->width, space_left);
 	    cdesc->width += fix;
======== end patch ======================================================

-- 
Chuck Goodhart <[email-masked]>

-----------------------------------------------------------------
 For information about this mailing list, and its archives, see: 
 http://www.washington.edu/pine/pine-info/
-----------------------------------------------------------------

---

From: Steve Hubert <[email-masked]>
Date: Tue, 15 Dec 1998 15:34:42 -0800 (PST)

Thanks! I like your table version. We'll use it.

-- 
Steve Hubert <[email-masked]>
Networks and Distributed Computing, Univ. of Washington, Seattle