Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: printf, left-justification ignored in 5.0.8
- X-seq: zsh-workers 35412
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: printf, left-justification ignored in 5.0.8
- Date: Sun, 07 Jun 2015 22:39:24 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1433709565; bh=P+4PW6zLehUiXN0Qkn1skOZ2B5lzRUukaSXNc6bXCaM=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=AJuOpeCPxcV5dnwf34QFXj/L6p9EJB3w0FHvDsmkHnC92fWdJQSUmTjLoNPb00Ju42AdHSwKrth8ji2ZTSkaeIiOq2laSSBusfllVNCQG1xMi1Jtez936GANZM4VDjAw8s0AF/wOPNWU8SyMG3ELN9VMzuyeR5eZxdT+/zFS+6d6ry3pT4YNesRCh2jF2Es879NycDXnv/hg5yLR7MI4K9gBL5LhQpihI/4n5X79bruEJbs42T7koPovkMM58H74zJrGl2sDmG072nf9B9wfMdB8UPjZ1no6gixdMmdRzzS0MRPIKmdb41vOZslmX/ErM7Q6DnOa4gr6bwLxKDEGSw==
- In-reply-to: <20150607081142.GF15174@isis.sigpipe.cz>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20150607081142.GF15174@isis.sigpipe.cz>
Roman Neuhauser wrote:
>
> 5.0.8:
>
> % printf "x:%-20s:y\n" fubar
> x: fubar:y
That'll be my fault for not checking thoroughly enough. The - flag is
fine for numeric values but for strings it seems there is separate code
to allow for UTF-8 which looks in the flags array. The patch should
fix this, adds a test and makes the maximum specification length test
include the ' flag.
Oliver
diff --git a/Src/builtin.c b/Src/builtin.c
index 9358e8b..8bfc419 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -4461,7 +4461,7 @@ bin_print(char *name, char **args, Options ops, int func)
lleft -= chars;
ptr += chars;
}
- if (width > 0 && flags[2]) width = -width;
+ if (width > 0 && flags[3]) width = -width;
if (width > 0 && lchars < width)
count += fprintf(fout, "%*c", width - lchars, ' ');
count += fwrite(b, 1, lbytes, fout);
diff --git a/Test/B03print.ztst b/Test/B03print.ztst
index 48574c2..9360416 100644
--- a/Test/B03print.ztst
+++ b/Test/B03print.ztst
@@ -169,11 +169,15 @@
0:%n count zeroed on format reuse
>1
-# this may fill spec string with '%0+- #*.*lld\0' - 13 characters
- printf '%1$0+- #-08.5dx\n' 123
+# this may fill spec string with '%0'+- #*.*lld\0' - 14 characters
+ printf '%1$0'"'+- #-08.5dx\n" 123
0:maximal length format specification
>+00123 x
+ printf "x:%-20s:y\n" fubar
+0:left-justification of string
+>x:fubar :y
+
printf '%*smorning\n' -5 good
0:negative width specified
>good morning
Messages sorted by:
Reverse Date,
Date,
Thread,
Author