Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: $var not expanded in ${x?$var}



On Tue, Feb 20, 2024 at 11:39 AM Stephane Chazelas
<stephane@xxxxxxxxxxxx> 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.
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 *);


Messages sorted by: Reverse Date, Date, Thread, Author