Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

'nother listing bug



-----BEGIN PGP SIGNED MESSAGE-----

I found a couple more bugs in the listing code.  First, the calculation
of "up" in listmatches() can go horribly wrong in some cases involving
rather long filenames (even if they're shorter than a line).  I'm not
sure exactly what the problem is, but it's fixed by applying the
zle_tricky.c part of patch 185 (which basically makes listmatches() use
nicefputs()).  I've updated that part of that patch, and it appears
below.  (The original no longer applies cleanly, and it's only a small
part of a patch the rest of which is in the baseline now.)

The second bug I found is that after getting an expansion listing (from
list-expand via listlist()), it is possible to get a "BUG: listmatches
called with bogus list" message by executing redisplay or
clear-screen.  This is fixed by the last hunk of the patch below, which
simply resets showinglist after displaying the expansion list.

 -zefram

      *** Src/zle_tricky.c	Thu Dec 21 07:56:02 1995
      --- Src/zle_tricky.c	Thu Dec 21 07:54:48 1995
      ***************
      *** 3563,3571 ****
        listmatches(void)
        {
            int longest = 1, fct, fw = 0, colsz, t0, t1, ct, up, cl, xup = 0;
      !     int off, boff;
            int of = (isset(LISTTYPES) && !(haswhat & HAS_MISC));
            char **arr, **ap, sav;
        
            /* Sanity check */
            if(!validlist) {
      --- 3563,3572 ----
        listmatches(void)
        {
            int longest = 1, fct, fw = 0, colsz, t0, t1, ct, up, cl, xup = 0;
      !     int off, boff, nboff;
            int of = (isset(LISTTYPES) && !(haswhat & HAS_MISC));
            char **arr, **ap, sav;
      +     int nfpl, nfsl, nlpl, nlsl;
        
            /* Sanity check */
            if(!validlist) {
      ***************
      *** 3575,3580 ****
      --- 3576,3587 ----
        	return;
            }
        
      +     /* Calculate lengths of prefixes/suffixes to be added */
      +     nfpl = fpre ? nicestrlen(fpre) : 0;
      +     nfsl = fsuf ? nicestrlen(fsuf) : 0;
      +     nlpl = lpre ? nicestrlen(lpre) : 0;
      +     nlsl = lsuf ? nicestrlen(lsuf) : 0;
      + 
            /* Calculate the lengths of the prefizes/suffizes we have to ignore
               during printing. */
            off = ispattern && ppre && *ppre &&
      ***************
      *** 3581,3586 ****
      --- 3588,3595 ----
        	!(haswhat & (HAS_MISC | HAS_PATHPAT)) ? strlen(ppre) : 0;
            boff = ispattern && psuf && *psuf &&
        	!(haswhat & (HAS_MISC | HAS_PATHPAT)) ? strlen(psuf) : 0;
      +     nboff = ispattern && psuf && *psuf &&
      + 	!(haswhat & (HAS_MISC | HAS_PATHPAT)) ? nicestrlen(psuf) : 0;
        
            /* When called from expandorcompleteprefix, we probably have to
               remove a space now. */
      ***************
      *** 3607,3615 ****
            /* Calculate the column width, the number of columns and the number
               of lines. */
            for (ap = arr; *ap; ap++)
      ! 	if ((cl = strlen(*ap + off) - boff +
        	     (ispattern ? 0 :
      ! 	      (!(haswhat & HAS_MISC) ? fpl + fsl : lpl + lsl))) > longest)
        	    longest = cl;
            if (of)
        	longest++;
      --- 3616,3624 ----
            /* Calculate the column width, the number of columns and the number
               of lines. */
            for (ap = arr; *ap; ap++)
      ! 	if ((cl = nicestrlen(*ap + off) - nboff +
        	     (ispattern ? 0 :
      ! 	      (!(haswhat & HAS_MISC) ? nfpl + nfsl : nlpl + nlsl))) > longest)
        	    longest = cl;
            if (of)
        	longest++;
      ***************
      *** 3620,3628 ****
        	colsz = ct;
        	up = colsz + nlnct - clearflag;
        	for (ap = arr; *ap; ap++)
      ! 	    up += (strlen(*ap + off) - boff + of +
        		(ispattern ? 0 :
      ! 		(!(haswhat & HAS_MISC) ? fpl + fsl : lpl + lsl))) / columns;
            } else {
        	fw = (columns - 1) / fct;
        	colsz = (ct + fct - 1) / fct;
      --- 3629,3637 ----
        	colsz = ct;
        	up = colsz + nlnct - clearflag;
        	for (ap = arr; *ap; ap++)
      ! 	    up += (nicestrlen(*ap + off) - nboff + of +
        		(ispattern ? 0 :
      ! 		(!(haswhat & HAS_MISC) ? nfpl + nfsl : nlpl + nlsl))) / columns;
            } else {
        	fw = (columns - 1) / fct;
        	colsz = (ct + fct - 1) / fct;
      ***************
      *** 3669,3689 ****
        	if (of) {
        	    /* We have to print the file types. */
        	    while (*ap) {
      ! 		int t2 = ispattern ? strlen(*ap) :
      ! 		strlen(*ap + off) - boff + 1 + fpl + fsl;
        		char *pb;
        		struct stat buf;
        
        		/* Build the path name for the stat. */
        		if (ispattern) {
      ! 		    sav = ap[0][t2 - boff];
      ! 		    ap[0][t2 - boff] = '\0';
      ! 		    fprintf(shout, "%s", *ap + off);
      ! 		    ap[0][t2 - boff] = sav;
        		    pb = *ap;
      - 		    t2 -= off + boff - 1;
        		} else {
      ! 		    fprintf(shout, "%s%s%s", fpre, *ap, fsuf);
        		    pb = (char *) ncalloc((prpre ? strlen(prpre) : 0) + 3 +
        					  strlen(fpre) + strlen(*ap) + strlen(fsuf));
        		    sprintf(pb, "%s%s%s%s",
      --- 3678,3702 ----
        	if (of) {
        	    /* We have to print the file types. */
        	    while (*ap) {
      ! 		int t2;
        		char *pb;
        		struct stat buf;
        
        		/* Build the path name for the stat. */
        		if (ispattern) {
      ! 		    int cut = strlen(*ap) - boff;
      ! 
      ! 		    sav = ap[0][cut];
      ! 		    ap[0][cut] = '\0';
      ! 		    nicefputs(*ap + off, shout);
      ! 		    t2 = nicestrlen(*ap + off);
      ! 		    ap[0][cut] = sav;
        		    pb = *ap;
        		} else {
      ! 		    nicefputs(fpre, shout);
      ! 		    nicefputs(*ap, shout);
      ! 		    nicefputs(fsuf, shout);
      ! 		    t2 = nfpl + nicestrlen(*ap) + nfsl;
        		    pb = (char *) ncalloc((prpre ? strlen(prpre) : 0) + 3 +
        					  strlen(fpre) + strlen(*ap) + strlen(fsuf));
        		    sprintf(pb, "%s%s%s%s",
      ***************
      *** 3697,3722 ****
        		for (t0 = colsz; t0 && *ap; t0--, ap++);
        		if (*ap)
        		    /* And add spaces to make the columns aligned. */
      ! 		    for (; t2 < fw; t2++)
        			putc(' ', shout);
        	    }
        	} else
        	    while (*ap) {
      ! 		int t2 = ispattern ? strlen(*ap) :
      ! 		strlen(*ap + off) - boff;
        
        		if (ispattern) {
      ! 		    sav = ap[0][t2 - boff];
      ! 		    ap[0][t2 - boff] = '\0';
      ! 		    fprintf(shout, "%s", *ap + off);
      ! 		    ap[0][t2 - boff] = sav;
      ! 		    t2 -= off + boff;
        		} else if (!(haswhat & HAS_MISC)) {
      ! 		    fprintf(shout, "%s%s%s", fpre, *ap, fsuf);
      ! 		    t2 += fpl + fsl;
        		} else {
      ! 		    fprintf(shout, "%s%s%s", lpre, *ap, lsuf);
      ! 		    t2 += lpl + lsl;
        		}
        		for (t0 = colsz; t0 && *ap; t0--, ap++);
        		if (*ap)
      --- 3710,3740 ----
        		for (t0 = colsz; t0 && *ap; t0--, ap++);
        		if (*ap)
        		    /* And add spaces to make the columns aligned. */
      ! 		    for (++t2; t2 < fw; t2++)
        			putc(' ', shout);
        	    }
        	} else
        	    while (*ap) {
      ! 		int t2;
        
        		if (ispattern) {
      ! 		    int cut = strlen(*ap) - boff;
      ! 
      ! 		    sav = ap[0][cut];
      ! 		    ap[0][cut] = '\0';
      ! 		    nicefputs(*ap + off, shout);
      ! 		    t2 = nicestrlen(*ap + off);
      ! 		    ap[0][cut] = sav;
        		} else if (!(haswhat & HAS_MISC)) {
      ! 		    nicefputs(fpre, shout);
      ! 		    nicefputs(*ap, shout);
      ! 		    nicefputs(fsuf, shout);
      ! 		    t2 = nfpl + nicestrlen(*ap) + nfsl;
        		} else {
      ! 		    nicefputs(lpre, shout);
      ! 		    nicefputs(*ap, shout);
      ! 		    nicefputs(lsuf, shout);
      ! 		    t2 = nlpl + nicestrlen(*ap) + nlsl;
        		}
        		for (t0 = colsz; t0 && *ap; t0--, ap++);
        		if (*ap)
      ***************
      *** 3756,3761 ****
      --- 3774,3780 ----
        
            makearray(l);
            listmatches();
      +     showinglist = 0;
        
            expl = ex;
            amatches = am;

-----BEGIN PGP SIGNATURE-----
Version: 2.6.i

iQCVAgUBMNkW6HD/+HJTpU/hAQEHVwQAsz8t1lgcNY9siAzXBUdCOmuRIgBt1+ZB
SpuOrQFHnH8XrdWTRmElKUQJ42ojvwbU2GpF9DTxYq0kodSXIP62EUdJoYZg85+o
ejknU05p6FB2cfgdI86zKMLxE41BKsnDUE+9e2WYXHZXE0W7kYdFcCHU3d25U8S7
EvEszUX07OI=
=oz4v
-----END PGP SIGNATURE-----



Messages sorted by: Reverse Date, Date, Thread, Author