1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-06-10 18:58:03 +02:00

52612: %l replacment of zwarning() does literal string output

This commit is contained in:
Bart Schaefer 2024-03-02 09:22:43 -08:00
parent 13f73d84d3
commit 4fb96cc639
4 changed files with 25 additions and 16 deletions

View file

@ -1,3 +1,9 @@
2024-03-02 Bart Schaefer <schaefer@zsh.org>
* 52612: Src/parse.c, Src/subst.c, Src/utils.c: change the %l
replacment of zwarning() et al. to do literal string output;
change previous uses to %s and use new %l for ${var?$error}
2024-03-01 Bart Schaefer <schaefer@zsh.org> 2024-03-01 Bart Schaefer <schaefer@zsh.org>
* 52645: Src/builtin.c: unset through a nameref keep up-scope * 52645: Src/builtin.c: unset through a nameref keep up-scope

View file

@ -2730,11 +2730,10 @@ yyerror(int noerr)
if (!t || !t[t0] || t[t0] == '\n') if (!t || !t[t0] || t[t0] == '\n')
break; break;
if (!(histdone & HISTFLAG_NOEXEC) && !(errflag & ERRFLAG_INT)) { if (!(histdone & HISTFLAG_NOEXEC) && !(errflag & ERRFLAG_INT)) {
if (t0 == 20) if (t0) {
zwarn("parse error near `%l...'", t, 20); t = metafy(t, t0, META_STATIC);
else if (t0) zwarn("parse error near `%s%s'", t, t0 == 20 ? "..." : "");
zwarn("parse error near `%l'", t, t0); } else
else
zwarn("parse error"); zwarn("parse error");
} }
if (!noerr && noerrs != 2) if (!noerr && noerrs != 2)

View file

@ -3271,8 +3271,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
if (isset(EXECOPT)) { if (isset(EXECOPT)) {
*idend = '\0'; *idend = '\0';
if (*s){ if (*s){
int l;
singsub(&s); singsub(&s);
zerr("%s: %s", idbeg, s); s = unmetafy(s, &l);
zerr("%s: %l", idbeg, s, l);
} else } else
zerr("%s: %s", idbeg, "parameter not set"); zerr("%s: %s", idbeg, "parameter not set");
/* /*

View file

@ -122,14 +122,20 @@ set_widearray(char *mb_array, Widechar_array wca)
(implemented by zerrmsg()): (implemented by zerrmsg()):
Code Argument types Prints Code Argument types Prints
%s const char * C string (null terminated) %s const char * C string (metafied, null terminated)
%l const char *, int C string of given length (null not required) (output "nice")
%l const char *, int C string of given length (not metafied)
(output raw)
%L long decimal value %L long decimal value
%d int decimal value %d int decimal value
%z zlong decimal value %z zlong decimal value
%% (none) literal '%' %% (none) literal '%'
%c int character at that codepoint %c int character at that codepoint
%e int strerror() message (argument is typically 'errno') %e int strerror() message (argument usually 'errno')
(output raw)
For %s and %l, the caller is responsible for assuring end-of-string
is not in the middle of a metafy pair (%s) or a multibyte character.
*/ */
static void static void
@ -310,14 +316,9 @@ zerrmsg(FILE *file, const char *fmt, va_list ap)
nicezputs(str, file); nicezputs(str, file);
break; break;
case 'l': { case 'l': {
char *s;
str = va_arg(ap, const char *); str = va_arg(ap, const char *);
num = va_arg(ap, int); num = va_arg(ap, int);
num = metalen(str, num); fwrite(str, num, 1, file);
s = zhalloc(num + 1);
memcpy(s, str, num);
s[num] = '\0';
nicezputs(s, file);
break; break;
} }
case 'L': case 'L':
@ -715,7 +716,8 @@ wcs_nicechar(wchar_t c, size_t *widthp, char **swidep)
*/ */
/**/ /**/
mod_export int is_wcs_nicechar(wchar_t c) mod_export int
is_wcs_nicechar(wchar_t c)
{ {
if (!WC_ISPRINT(c) && (c < 0x80 || !isset(PRINTEIGHTBIT))) { if (!WC_ISPRINT(c) && (c < 0x80 || !isset(PRINTEIGHTBIT))) {
if (c == 0x7f || c == L'\n' || c == L'\t' || c < 0x20) if (c == 0x7f || c == L'\n' || c == L'\t' || c < 0x20)