zsh-users
 help / color / mirror / code / Atom feed
* typeset -Z broken?
@ 1999-09-05 12:57 Gabor
  1999-09-06 15:19 ` typeset -Z broken? -R broken too? Gabor
  0 siblings, 1 reply; 3+ messages in thread
From: Gabor @ 1999-09-05 12:57 UTC (permalink / raw)
  To: zsh-users

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

typeset -Z10 nname
for name in *; do
    if (( ${#name} < 10 )) then
	nname=$name
	mv $name $nname
    fi
done


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: typeset -Z broken? -R broken too?
  1999-09-05 12:57 typeset -Z broken? Gabor
@ 1999-09-06 15:19 ` Gabor
  0 siblings, 0 replies; 3+ messages in thread
From: Gabor @ 1999-09-06 15:19 UTC (permalink / raw)
  To: zsh-users

It appears that -R is broken, too.

Here is output of ksh with -R
=== gabor $ typeset -R20 name;for name in *;do print "$name";done
                bin/
     sample-scripts/
           software/
               test/
=== gabor $ 

And here is zsh
=== gabor $ typeset -R20 name;for name in *;do print "$name";done
bin/
sample-scripts/
software/
test/
=== gabor $ 

Also, even with the fix here is zsh for -Z
=== gabor $ typeset -Z20 name;for name in *;do print "$name";done
bin/
sample-scripts/
software/
test/
=== gabor $ 

And here is ksh
=== gabor $ typeset -Z20 name;for name in *;do print "$name";done
                bin/
     sample-scripts/
           software/
               test/
=== gabor $ 

Here they are with 0 prefix for test dir
ksh
=== gabor $ typeset -Z20 name;for name in *;do print "$name";done
000000000000000test/
                bin/
     sample-scripts/
           software/
=== gabor $ 

zsh
=== gabor $ typeset -Z20 name;for name in *;do print "$name";done
000000000000000test/
bin/
sample-scripts/
software/
=== gabor $ 


:(

On Sun, Sep 05, 1999 at 08:57:22AM -0400, 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
# 
# typeset -Z10 nname
# for name in *; do
#     if (( ${#name} < 10 )) then
# 	nname=$name
# 	mv $name $nname
#     fi
# done


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: typeset -Z broken?
@ 1999-09-06 12:33 Sven Wischnowsky
  0 siblings, 0 replies; 3+ messages in thread
From: Sven Wischnowsky @ 1999-09-06 12:33 UTC (permalink / raw)
  To: zsh-users


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@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1999-09-06 16:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-05 12:57 typeset -Z broken? Gabor
1999-09-06 15:19 ` typeset -Z broken? -R broken too? Gabor
1999-09-06 12:33 typeset -Z broken? Sven Wischnowsky

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).