zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: $var not expanded in ${x?$var}
Date: Tue, 20 Feb 2024 20:44:47 -0800	[thread overview]
Message-ID: <CAH+w=7YmczEa2rNa68OwUhiRArBFJ11FdwT6Qci_LmTAWFauGg@mail.gmail.com> (raw)
In-Reply-To: <20240220193911.avnmcqfliwltkj5m@chazelas.org>

[-- Attachment #1: Type: text/plain, Size: 577 bytes --]

On Tue, Feb 20, 2024 at 11:39 AM Stephane Chazelas
<stephane@chazelas.org> wrote:
>
> Looking at https://austingroupbugs.net/view.php?id=1771 where
> availability of printf %X directives is discussed, looks like %S
> is the least likely to conflict with printf(3) or printf(1) if
> that was ever to be a concern.

Zsh contains approximately 500 calls to output error messages, at
least a third of which include strings that would have come from user
input.  I wonder how many of those are eventually going to want %S or
at least some less-than-"nice" processing.

[-- Attachment #2: zerr%S.txt --]
[-- Type: text/plain, Size: 1156 bytes --]

diff --git a/Src/subst.c b/Src/subst.c
index 650c09de2..ddf9f9de9 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -3272,7 +3272,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
                     *idend = '\0';
 		    if (*s){
 			singsub(&s);
-			zerr("%s: %s", idbeg, s);
+			zerr("%s: %S", idbeg, s);
 		    } else
 			zerr("%s: %s", idbeg, "parameter not set");
                     /*
diff --git a/Src/utils.c b/Src/utils.c
index 0fda92709..0482f3316 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -123,6 +123,7 @@ set_widearray(char *mb_array, Widechar_array wca)
 
    Code	Argument types		Prints
    %s	const char *		C string (null terminated)
+   %S	const char *		C string (null terminated), output raw
    %l	const char *, int	C string of given length (null not required)
    %L	long			decimal value
    %d	int			decimal value
@@ -309,6 +310,10 @@ zerrmsg(FILE *file, const char *fmt, va_list ap)
 		str = va_arg(ap, const char *);
 		nicezputs(str, file);
 		break;
+	    case 'S':
+		str = va_arg(ap, const char *);
+		fprintf(file, "%s", str);
+		break;
 	    case 'l': {
 		char *s;
 		str = va_arg(ap, const char *);

  reply	other threads:[~2024-02-21  4:45 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-13  8:02 Stephane Chazelas
2023-01-16  8:35 ` Daniel Shahaf
2023-01-16 17:15 ` Peter Stephenson
2024-02-20  7:05   ` Stephane Chazelas
2024-02-20 17:45     ` Bart Schaefer
2024-02-20 19:39       ` Stephane Chazelas
2024-02-21  4:44         ` Bart Schaefer [this message]
2024-02-21 19:45           ` Stephane Chazelas
2024-02-21 19:52             ` Bart Schaefer
2024-02-21 20:21               ` Stephane Chazelas
2024-02-22  0:46                 ` [PATCH] unmetafy " Bart Schaefer
2024-02-22  7:23                   ` Stephane Chazelas
2024-02-22  7:55                     ` Metafication in error messages (Was: [PATCH] unmetafy Re: $var not expanded in ${x?$var}) Stephane Chazelas
2024-02-22 17:02                       ` Bart Schaefer
2024-02-22 22:31                         ` Bart Schaefer
2024-02-23  0:49                           ` Bart Schaefer
2024-02-23 19:27                           ` Stephane Chazelas
2024-02-23 22:32                             ` Bart Schaefer
2024-02-23 23:38                               ` Bart Schaefer
2024-02-24  9:47                               ` Stephane Chazelas
2024-02-24 10:36                                 ` Stephane Chazelas
2024-02-25  4:35                                   ` [PATCH] 'bad interpreter' error garbled Bart Schaefer
2024-02-25  5:26                                     ` Bart Schaefer
2024-02-25  2:17                                 ` Metafication in error messages (Was: [PATCH] unmetafy Re: $var not expanded in ${x?$var}) Bart Schaefer
2024-02-25  6:05                                   ` Bart Schaefer
2024-02-25  7:29                                     ` Stephane Chazelas
2024-02-25  8:28                                       ` typeset -<non-ASCII> (Was: metafication in error messages) Stephane Chazelas
2024-02-25  8:35                                         ` Stephane Chazelas
2024-02-25 21:02                                         ` Bart Schaefer
2024-02-23  0:33                       ` Metafication in error messages (Was: [PATCH] unmetafy Re: $var not expanded in ${x?$var}) Bart Schaefer
2024-02-25  5:06                       ` [PATCH] count multibyte and metafied characters correctly for math ops errors Bart Schaefer
2024-02-22  8:34                     ` [PATCH] unmetafy Re: $var not expanded in ${x?$var} Roman Perepelitsa
2024-02-22 17:07                       ` Bart Schaefer

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='CAH+w=7YmczEa2rNa68OwUhiRArBFJ11FdwT6Qci_LmTAWFauGg@mail.gmail.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).