zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: "Zsh Hackers' List" <zsh-workers@zsh.org>
Subject: Re: printf \045 (or whatever the character code for % is)
Date: Thu, 06 Jan 2011 08:01:40 -0800	[thread overview]
Message-ID: <110106080140.ZM10129@torch.brasslantern.com> (raw)
In-Reply-To: <20110106120959.2a4691f3@pwslap01u.europe.root.pri>

On Jan 6, 12:09pm, Peter Stephenson wrote:
> Subject: Re: printf \045 (or whatever the character code for % is)
>
> On Wed, 5 Jan 2011 20:46:12 -0800
> Bart Schaefer <schaefer@brasslantern.com> wrote:
> > GETKEYS_PRINTF_FMT expands to GETKEY_OCTAL_ESC|GETKEY_BACKSLASH_C ...
> > seems as though an additional flag to getkeystring() could be used to
> > cause \045 to expand to %% as a special case, something like this in
> > utils.c:
> 
> That's sneaky, that should be OK.
> 
> Presumably since we're contracting an escape sequence there's always enough
> allocated space for the extra '%'.

It's a bit hard to follow getkeystring() in the multibyte branches,
but as that should always be allocating more rather than less space,
I believe the answer is "that's correct".  Minimum it's \45 -> %%.

> Unless we go down the route of separate builtin handlers, I think it
> would be better to keep printf and print -f in sync for now.

In that case, no need to touch builtin.c at all.

> [...] we haven't yet gone into the details of where printf actually
> needs to be different from print (we'd need to look at the relevant
> standards for printf to see where the code is doing the wrong thing at
> present).

For one thing, hasn't austin-group been discussing \Cx where zsh at
present uses the old Emacs syntax of \C-x ?

(Revision numbers below are from my local repository, ignore them.)

Index: Src/utils.c
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-4.0/Src/utils.c,v
retrieving revision 1.40
diff -c -r1.40 utils.c
--- utils.c	21 Dec 2010 16:41:16 -0000	1.40
+++ utils.c	6 Jan 2011 15:43:40 -0000
@@ -5517,6 +5522,8 @@
 		    }
 		    *t++ = zstrtol(s + (*s == 'x'), &s,
 				   (*s == 'x') ? 16 : 8);
+		    if ((how & GETKEY_PRINTF_PERCENT) && t[-1] == '%')
+		        *t++ = '%';
 		    if (svchar) {
 			u[3] = svchar;
 			svchar = '\0';
Index: Src/zsh.h
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-4.0/Src/zsh.h,v
retrieving revision 1.43
diff -c -r1.43 zsh.h
--- zsh.h	21 Dec 2010 16:41:16 -0000	1.43
+++ zsh.h	6 Jan 2011 15:50:06 -0000
@@ -2492,7 +2492,11 @@
      * Yes, I know that doesn't seem to make much sense.
      * It's for use in completion, comprenez?
      */
-    GETKEY_UPDATE_OFFSET = (1 << 7)
+    GETKEY_UPDATE_OFFSET = (1 << 7),
+    /*
+     * When replacing numeric escapes for printf format strings, % -> %%
+     */
+    GETKEY_PRINTF_PERCENT = (1 << 8)
 };
 
 /*
@@ -2501,8 +2505,9 @@
  */
 /* echo builtin */
 #define GETKEYS_ECHO	(GETKEY_BACKSLASH_C)
-/* printf format string:  \123 -> S, \0123 -> NL 3 */
-#define GETKEYS_PRINTF_FMT	(GETKEY_OCTAL_ESC|GETKEY_BACKSLASH_C)
+/* printf format string:  \123 -> S, \0123 -> NL 3, \045 -> %% */
+#define GETKEYS_PRINTF_FMT	\
+        (GETKEY_OCTAL_ESC|GETKEY_BACKSLASH_C|GETKEY_PRINTF_PERCENT)
 /* printf argument:  \123 -> \123, \0123 -> S */
 #define GETKEYS_PRINTF_ARG	(GETKEY_BACKSLASH_C)
 /* Full print without -e */


      reply	other threads:[~2011-01-06 16:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-29 21:11 Jilles Tjoelker
2010-12-29 23:55 ` Alexey I. Froloff
2011-01-05 17:39 ` Peter Stephenson
2011-01-06  4:46   ` Bart Schaefer
2011-01-06 12:09     ` Peter Stephenson
2011-01-06 16:01       ` Bart Schaefer [this message]

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=110106080140.ZM10129@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --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).