From 8eaa03b7c9bacf1dd9883408e2dbe4a31d3173f6 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Tue, 18 May 2021 13:02:56 +0200 Subject: [PATCH] conf: print quoted string more wisely Signed-off-by: Jaroslav Kysela --- src/conf.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/conf.c b/src/conf.c index 5c977266..d66e186d 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1508,6 +1508,7 @@ static int parse_defs(snd_config_t *parent, input_t *input, int skip, int overri static void string_print(char *str, int id, snd_output_t *out) { + int q; unsigned char *p = (unsigned char *)str; if (!p || !*p) { snd_output_puts(out, "''"); @@ -1549,7 +1550,8 @@ static void string_print(char *str, int id, snd_output_t *out) snd_output_puts(out, str); return; quoted: - snd_output_putc(out, '\''); + q = strchr(str, '\'') ? '"' : '\''; + snd_output_putc(out, q); p = (unsigned char *)str; while (*p) { int c; @@ -1579,20 +1581,21 @@ static void string_print(char *str, int id, snd_output_t *out) snd_output_putc(out, '\\'); snd_output_putc(out, 'f'); break; - case '\'': - snd_output_putc(out, '\\'); - snd_output_putc(out, c); - break; default: - if (c >= 32 && c <= 126 && c != '\'') + if (c == q) { + snd_output_putc(out, '\\'); snd_output_putc(out, c); - else - snd_output_printf(out, "\\%04o", c); + } else { + if (c >= 32 && c <= 126) + snd_output_putc(out, c); + else + snd_output_printf(out, "\\%04o", c); + } break; } p++; } - snd_output_putc(out, '\''); + snd_output_putc(out, q); } static void level_print(snd_output_t *out, unsigned int level) -- 2.11.0