From 08e8fd7e38f2dae7c69c54eb22d508b6517e66e5 Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Sun, 1 Nov 2015 18:53:26 +0000 Subject: all: avoid quoting file names when possible Quote file names using the "shell-escape" or "shell-escape-always" methods, which quote as appropriate for most shells, and better support copy and paste of presented names. The "always" variant is used when the file name is embedded in an error message with surrounding spaces. * cfg.mk (sc_error_shell_quotes): A new syntax check rule to suggest quotef() where appropriate. (sc_error_shell_always_quotes): Likewise for quoteaf(). * src/system.h (quotef): A new define to apply shell quoting when needed. I.E. when shell character or ':' is present. (quoteaf): Likewise, but always quote. * src/*.c: Use quotef() and quoteaf() rather than quote() where appropriate. * tests/: Adjust accordingly. --- src/system.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/system.h') diff --git a/src/system.h b/src/system.h index 1cd6bdb44..ded187f83 100644 --- a/src/system.h +++ b/src/system.h @@ -693,7 +693,7 @@ WARNING: Circular directory structure.\n\ This almost certainly means that you have a corrupted file system.\n\ NOTIFY YOUR SYSTEM MANAGER.\n\ The following directory is part of the cycle:\n %s\n"), \ - quote (file_name)); \ + quotef (file_name)); \ } \ while (0) @@ -731,3 +731,22 @@ is_ENOTSUP (int err) { return err == EOPNOTSUPP || (ENOTSUP != EOPNOTSUPP && err == ENOTSUP); } + + +/* How coreutils quotes filenames, to minimize use of outer quotes, + but also provide better support for copy and paste when used. */ +#include "quotearg.h" + +/* Use these to shell quote only when necessary, + when the quoted item is already delimited with colons. */ +#define quotef(arg) \ + quotearg_n_style_colon (0, shell_escape_quoting_style, arg) +#define quotef_n(n, arg) \ + quotearg_n_style_colon (n, shell_escape_quoting_style, arg) + +/* Use these when there are spaces around the file name, + in the error message. */ +#define quoteaf(arg) \ + quotearg_style (shell_escape_always_quoting_style, arg) +#define quoteaf_n(n, arg) \ + quotearg_n_style (n, shell_escape_always_quoting_style, arg) -- cgit v1.2.3-54-g00ecf