From: "Thorsten Dahlheimer" <tdahlheim@gmx.net>
To: "Wayne Davison" <wayned@users.sourceforge.net>
Cc: <zsh-workers@sunsite.dk>
Subject: Re: PATCH: Expansion of \c escape sequences
Date: Sun, 24 Jul 2005 20:09:40 +0200 [thread overview]
Message-ID: <00c701c5907a$df03b860$b63dfea9@pcdahl4201> (raw)
In-Reply-To: <20050724055220.GA19554@blorf.net>
[-- Attachment #1: Type: text/plain, Size: 601 bytes --]
Wayne Davison wrote:
> I'm curious which version of coreutils behaves that way? I've got 5.2.1
> on my system, and it behaves as zsh does.
Indeed, echo seems to have been changed after the 5.2.1 release (I tested
with 5.3.0). Printf behaves as I described even in 5.2.1, though.
> If we want to change the
> behavior, the attached patch should handle it.
Not quite, since it doesn't handle these cases:
%/usr/bin/echo -e 'a\c' b
a
%/usr/bin/printf '%s\c%s' a b c
a
%/usr/bin/printf '%b %b\n' a b 'c\c' d e
a b
c
I've attached an extended patch that should do this.
Regards,
Thorsten Dahlheimer
[-- Attachment #2: backslash-c_2.patch --]
[-- Type: application/octet-stream, Size: 2727 bytes --]
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.140
diff -u -p -r1.140 builtin.c
--- Src/builtin.c 17 Jun 2005 08:37:46 -0000 1.140
+++ Src/builtin.c 24 Jul 2005 17:39:28 -0000
@@ -3284,7 +3284,7 @@ int
bin_print(char *name, char **args, Options ops, int func)
{
int flen, width, prec, type, argc, n, narg;
- int nnl = 0, ret = 0, maxarg = 0;
+ int nnl = 0, ret = 0, maxarg = 0, fmtbsc = 0;
int flags[5], *len;
char *start, *endptr, *c, *d, *flag, *buf, spec[13], *fmt = NULL;
char **first, *curarg, *flagch = "0+- #", save = '\0', nullstr = '\0';
@@ -3313,7 +3313,7 @@ bin_print(char *name, char **args, Optio
else if (OPT_HASARG(ops,'f'))
fmt = OPT_ARG(ops,'f');
if (fmt)
- fmt = getkeystring(fmt, &flen, OPT_ISSET(ops,'b') ? 2 : 0, &nnl);
+ fmt = getkeystring(fmt, &flen, OPT_ISSET(ops,'b') ? 2 : 0, &fmtbsc);
first = args;
@@ -3349,10 +3349,15 @@ bin_print(char *name, char **args, Optio
(!OPT_ISSET(ops,'e') &&
(OPT_ISSET(ops,'R') || OPT_ISSET(ops,'r') || OPT_ISSET(ops,'E'))))
unmetafy(args[n], &len[n]);
- else
+ else {
args[n] = getkeystring(args[n], &len[n], OPT_ISSET(ops,'b') ? 2 :
(func != BIN_ECHO && !OPT_ISSET(ops,'e')),
&nnl);
+ if (nnl) {
+ args[n + 1] = NULL;
+ argc = n + 1;
+ }
+ }
/* -P option -- interpret as a prompt sequence */
if(OPT_ISSET(ops,'P')) {
/*
@@ -3754,6 +3759,8 @@ bin_print(char *name, char **args, Optio
if (width < 0 && l < -width)
printf("%*c", -width - l, ' ');
count += l;
+ if (nnl)
+ goto printf_finished;
}
break;
case 'q':
@@ -3854,8 +3861,9 @@ bin_print(char *name, char **args, Optio
if (maxarg) args = first + maxarg;
/* if there are remaining args, reuse format string */
- } while (*args && args != first && !OPT_ISSET(ops,'r'));
+ } while (*args && args != first && !fmtbsc && !OPT_ISSET(ops,'r'));
+printf_finished:
if (OPT_ISSET(ops,'z') || OPT_ISSET(ops,'s')) {
#ifdef HAVE_OPEN_MEMSTREAM
putc(0, fout);
Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.80
diff -u -p -r1.80 utils.c
--- Src/utils.c 24 Jul 2005 05:19:58 -0000 1.80
+++ Src/utils.c 24 Jul 2005 17:40:03 -0000
@@ -3611,7 +3611,9 @@ getkeystring(char *s, int *len, int from
case 'c':
if (fromwhere < 2) {
*misc = 1;
- break;
+ *t = '\0';
+ *len = t - buf;
+ return buf;
}
goto def;
case 'u':
next prev parent reply other threads:[~2005-07-24 18:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-24 2:15 Thorsten Dahlheimer
2005-07-24 5:52 ` Wayne Davison
2005-07-24 18:09 ` Thorsten Dahlheimer [this message]
2005-07-26 0:10 ` Wayne Davison
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='00c701c5907a$df03b860$b63dfea9@pcdahl4201' \
--to=tdahlheim@gmx.net \
--cc=wayned@users.sourceforge.net \
--cc=zsh-workers@sunsite.dk \
/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).