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. --- cfg.mk | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'cfg.mk') diff --git a/cfg.mk b/cfg.mk index 208f2ce80..78f19fa56 100644 --- a/cfg.mk +++ b/cfg.mk @@ -187,6 +187,37 @@ sc_error_quotes: exit 1; } \ || : +# Files in src/ should quote all file names in error() output +# using quotef(), to provide quoting only when necessary, +# but also provide better support for copy and paste when used. +sc_error_shell_quotes: + @cd $(srcdir)/src && \ + { GIT_PAGER= git grep -E \ + 'error \(.*%s[:"], .*(name|file)[^"]*\);$$' *.c; \ + GIT_PAGER= git grep -E \ + ' quote[ _].*file' *.c; } \ + | grep -Ev '(quotef|q[^ ]*name)' \ + && { echo '$(ME): '"Use quotef() for colon delimited names" 1>&2; \ + exit 1; } \ + || : + +# Files in src/ should quote all file names in error() output +# using quoteaf() when the name is separated with spaces, +# to distinguish the file name at issue and +# to provide better support for copy and paste. +sc_error_shell_always_quotes: + @cd $(srcdir)/src && GIT_PAGER= git grep -E \ + 'error \(.*[^:] %s[ "].*, .*(name|file)[^"]*\);$$' \ + *.c | grep -Ev '(quoteaf|q[^ ]*name)' \ + && { echo '$(ME): '"Use quoteaf() for space delimited names" 1>&2; \ + exit 1; } \ + || : + @cd $(srcdir)/src && GIT_PAGER= git grep -E -A1 \ + 'error \([^%]*[^:] %s[ "]' *.c | grep 'quotef' \ + && { echo '$(ME): '"Use quoteaf() for space delimited names" 1>&2; \ + exit 1; } \ + || : + sc_sun_os_names: @grep -nEi \ 'solaris[^[:alnum:]]*2\.(7|8|9|[1-9][0-9])|sunos[^[:alnum:]][6-9]' \ -- cgit v1.2.3-54-g00ecf