* PATCH: Expansion of \c escape sequences @ 2005-07-24 2:15 Thorsten Dahlheimer 2005-07-24 5:52 ` Wayne Davison 0 siblings, 1 reply; 4+ messages in thread From: Thorsten Dahlheimer @ 2005-07-24 2:15 UTC (permalink / raw) To: zsh-workers [-- Attachment #1: Type: text/plain, Size: 913 bytes --] Hi, I've noticed that in contexts where escape sequences are expanded and \c's should not be recognized (i.e., not in arguments to the various printing commands), then a \c is actually treated synonymous to \U. The attached patch contains a fix. While inspecting the code I came across another glitch: If a \c occurs in the separator string of a $arr[(pws:...:)...] subscript, it is not treated like an unrecognized sequence (i.e., replaced by a "c"), but removed completely. (Note that ${(p...)...} gets this right.) The attached patch also fixes that. Finally, I've discovered that \c in an argument to a printing command only suppresses the final newline, but according POSIX it should suppress all output after the \c, and that's what ksh, bash, and echo/printf from GNU coreutils do. So is the current behaviour really desired, or should I send a patch to change it? Best regards Thorsten Dahlheimer [-- Attachment #2: bsc.patch --] [-- Type: application/octet-stream, Size: 924 bytes --] Index: Src/utils.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/utils.c,v retrieving revision 1.78 diff -u -r1.78 utils.c --- Src/utils.c 31 Mar 2005 09:54:59 -0000 1.78 +++ Src/utils.c 24 Jul 2005 00:38:16 -0000 @@ -3611,6 +3611,7 @@ *misc = 1; break; } + goto def; case 'u': case 'U': wval = 0; Index: Src/params.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/params.c,v retrieving revision 1.98 diff -u -r1.98 params.c --- Src/params.c 8 Apr 2005 16:42:58 -0000 1.98 +++ Src/params.c 24 Jul 2005 00:37:52 -0000 @@ -1002,7 +1002,7 @@ goto flagerr; sav = *t; *t = '\0'; - sep = escapes ? getkeystring(s + 1, &waste, 1, &waste) : + sep = escapes ? getkeystring(s + 1, &waste, 3, NULL) : dupstring(s + 1); *t = sav; s = t; ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PATCH: Expansion of \c escape sequences 2005-07-24 2:15 PATCH: Expansion of \c escape sequences Thorsten Dahlheimer @ 2005-07-24 5:52 ` Wayne Davison 2005-07-24 18:09 ` Thorsten Dahlheimer 0 siblings, 1 reply; 4+ messages in thread From: Wayne Davison @ 2005-07-24 5:52 UTC (permalink / raw) To: Thorsten Dahlheimer; +Cc: zsh-workers [-- Attachment #1: Type: text/plain, Size: 678 bytes --] Thanks for the \c fixes and your earlier Makefile.in patch -- I've checked them into CVS (and I improved the function-comment for getkeystring() while I was at it). On Sun, Jul 24, 2005 at 04:15:12AM +0200, Thorsten Dahlheimer wrote: > Finally, I've discovered that \c in an argument to a printing command > only suppresses the final newline, but according POSIX it should > suppress all output after the \c, and that's what ksh, bash, and > echo/printf from GNU coreutils do. 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. If we want to change the behavior, the attached patch should handle it. ..wayne.. [-- Attachment #2: backslash-c.patch --] [-- Type: text/plain, Size: 320 bytes --] --- Src/utils.c 24 Jul 2005 05:19:58 -0000 1.80 +++ Src/utils.c 24 Jul 2005 05:42:08 -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': ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PATCH: Expansion of \c escape sequences 2005-07-24 5:52 ` Wayne Davison @ 2005-07-24 18:09 ` Thorsten Dahlheimer 2005-07-26 0:10 ` Wayne Davison 0 siblings, 1 reply; 4+ messages in thread From: Thorsten Dahlheimer @ 2005-07-24 18:09 UTC (permalink / raw) To: Wayne Davison; +Cc: zsh-workers [-- 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': ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PATCH: Expansion of \c escape sequences 2005-07-24 18:09 ` Thorsten Dahlheimer @ 2005-07-26 0:10 ` Wayne Davison 0 siblings, 0 replies; 4+ messages in thread From: Wayne Davison @ 2005-07-26 0:10 UTC (permalink / raw) To: Thorsten Dahlheimer; +Cc: zsh-workers On Sun, Jul 24, 2005 at 08:09:40PM +0200, Thorsten Dahlheimer wrote: > Not quite, since it doesn't handle these cases: [...] > I've attached an extended patch that should do this. Very nice. I tweaked it just a bit, and checked it in. Thanks! ..wayne.. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-07-26 0:10 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2005-07-24 2:15 PATCH: Expansion of \c escape sequences Thorsten Dahlheimer 2005-07-24 5:52 ` Wayne Davison 2005-07-24 18:09 ` Thorsten Dahlheimer 2005-07-26 0:10 ` Wayne Davison
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).