From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6534 invoked by alias); 6 Jan 2011 12:10:20 -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: 28577 Received: (qmail 7608 invoked from network); 6 Jan 2011 12:10:07 -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=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Thu, 6 Jan 2011 12:09:59 +0000 From: Peter Stephenson To: "Zsh Hackers' List" Subject: Re: printf \045 (or whatever the character code for % is) Message-ID: <20110106120959.2a4691f3@pwslap01u.europe.root.pri> In-Reply-To: <110105204614.ZM8225@torch.brasslantern.com> References: <20101229211155.GA22720@stack.nl> <20110105173944.47123402@pws-pc.ntlworld.com> <110105204614.ZM8225@torch.brasslantern.com> Organization: Cambridge Silicon Radio X-Mailer: Claws Mail 3.7.6 (GTK+ 2.20.1; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-OriginalArrivalTime: 06 Jan 2011 12:09:59.0973 (UTC) FILETIME=[A416FD50:01CBAD9A] X-Scanned-By: MailControl A_10_80_00 (www.mailcontrol.com) on 10.71.0.124 On Wed, 5 Jan 2011 20:46:12 -0800 Bart Schaefer wrote: > } The code for printf doesn't really have any business being > associated } with the code for print, they're there for different > purposes entirely } based on completely different specifications. At > the moment printf } does the same as 'print -f', so it has all the > same oddities as print } whether it should or not. >=20 > I'm not entirely sure that's true. The printf builtin doesn't accept > any options, which means that except for the initial getkeystring(), > nearly everything in bin_print() is ignored until you get down to the > part that handles the format spec ... and that can't be replaced by > e.g. sprintf() because of misc. special formats like %b and %q. That's kind of why print & printf really ought to be separate, with common subroutines where needed (the lack of modularity in bin_print() is one of the big issues). But that's moot for now... > 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. > @@ -5517,6 +5522,8 @@ > } > *t++ =3D zstrtol(s + (*s =3D=3D 'x'), &s, > (*s =3D=3D 'x') ? 16 : 8); > + if ((how & GETKEY_PRINTF) && t[-1] =3D=3D '%') > + *t++ =3D '%'; > if (svchar) { > u[3] =3D svchar; > svchar =3D '\0'; Presumably since we're contracting an escape sequence there's always enough allocated space for the extra '%'. > The flag bits for "how" are an enum in zsh.h and I'm undecided whether > to renumber them or just add another to the end, so I have't included > a complete patch. Also I don't know whether the intent is that \045 > (and \x25) should become %% only for "printf" or also for "print -f", > so no patch for builtin.c yet either. There's no particularly well-defined order in the enum, although the more recherch=C3=A9 options tend to be later (but only because they were added later). 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. For one thing, making them different puts yet another strain on bin_print(); for another, 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). --=20 Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, = UK Member of the CSR plc group of companies. CSR plc registered in England and= Wales, registered number 4187346, registered office Churchill House, Cambr= idge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom