From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh workers <zsh-workers@zsh.org>
Subject: Re: printf, left-justification ignored in 5.0.8
Date: Sun, 07 Jun 2015 22:39:24 +0200 [thread overview]
Message-ID: <30271.1433709564@thecus.kiddle.eu> (raw)
In-Reply-To: <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
next parent reply other threads:[~2015-06-07 20:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20150607081142.GF15174@isis.sigpipe.cz>
2015-06-07 20:39 ` Oliver Kiddle [this message]
2015-06-07 21:15 ` Stephane Chazelas
2015-06-12 11:30 ` Vincent Lefevre
2015-06-12 12:31 ` Stephane Chazelas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=30271.1433709564@thecus.kiddle.eu \
--to=okiddle@yahoo.co.uk \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).