From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20859 invoked by alias); 6 Jan 2011 16:02:16 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 28578 Received: (qmail 8783 invoked from network); 6 Jan 2011 16:02:13 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <110106080140.ZM10129@torch.brasslantern.com> Date: Thu, 06 Jan 2011 08:01:40 -0800 In-reply-to: <20110106120959.2a4691f3@pwslap01u.europe.root.pri> Comments: In reply to Peter Stephenson "Re: printf \045 (or whatever the character code for % is)" (Jan 6, 12:09pm) References: <20101229211155.GA22720@stack.nl> <20110105173944.47123402@pws-pc.ntlworld.com> <110105204614.ZM8225@torch.brasslantern.com> <20110106120959.2a4691f3@pwslap01u.europe.root.pri> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: "Zsh Hackers' List" Subject: Re: printf \045 (or whatever the character code for % is) MIME-version: 1.0 Content-type: text/plain; charset=us-ascii 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 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 */