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

Re: typeset -Z broken?



Gabor wrote:

> Here is the relevant part of the man page
> 
> 
>               -Z     Right justify and fill with leading zeros if
>                      the first non-blank character is a digit and
>                      the  -L  flag  has  not  been  set.  If n is
>                      nonzero it defines the width of  the  field;
>                      otherwise  it  is determined by the width of
>                      the value of the first assignment.
> 
> yet, when I use this I get left padding with zeros even on names that don't
> start with a digit

Hm, I hope this makes it work the way it should.

Bye
 Sven

--- os/subst.c	Mon Sep  6 13:08:29 1999
+++ Src/subst.c	Mon Sep  6 14:31:44 1999
@@ -1143,12 +1143,21 @@
 		case PM_RIGHT_Z:
 		case PM_RIGHT_Z | PM_RIGHT_B:
 		    if (strlen(val) < fwidth) {
-			t = (char *)ncalloc(fwidth + 1);
-			memset(t, (v->pm->flags & PM_RIGHT_B) ? ' ' : '0', fwidth);
-			if ((t0 = strlen(val)) > fwidth)
-			    t0 = fwidth;
-			strcpy(t + (fwidth - t0), val);
-			val = t;
+			t = NULL;
+			if (v->pm->flags & PM_RIGHT_Z) {
+			    for (t = val; iblank(*t); t++);
+			    if (t && idigit(*t))
+				val = t, t = NULL;
+			}
+			if (!t) {
+			    t = (char *)ncalloc(fwidth + 1);
+			    memset(t, (v->pm->flags & PM_RIGHT_B) ? ' ' : '0', 
+				   fwidth);
+			    if ((t0 = strlen(val)) > fwidth)
+				t0 = fwidth;
+			    strcpy(t + (fwidth - t0), val);
+			    val = t;
+			}
 		    } else {
 			t = (char *)ncalloc(fwidth + 1);
 			t[fwidth] = '\0';

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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