autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] m4sh: Add _AS_INVOCATION


From: Eric Blake
Subject: [PATCH 1/2] m4sh: Add _AS_INVOCATION
Date: Thu, 22 Dec 2016 11:17:01 -0600

When outputting a script's command line to a log file, it helps
if we quote arguments suitable for re-pasting into a shell command
line.  Since we have more than one site (configure and config.status)
that weren't doing this, it helps if we first add an m4sh primitive
for easily creating this format, while minimizing forks and quoting
on arguments that don't need special handling.

For now, I've kept the macro undocumented; if there is demand, we
can promote it to the stable name AS_INVOCATION and add it to the
manual.

* lib/m4sugar/m4sh.m4 (_AS_INVOCATION): New macro.
* tests/m4sh.at (_AS@&address@hidden): Test it.
Inspired by a report by Kevin Brubeck Unhammer <address@hidden>.
Signed-off-by: Eric Blake <address@hidden>
---
 lib/m4sugar/m4sh.m4 | 14 ++++++++++++++
 tests/m4sh.at       | 23 +++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 3b37683..e0470ed 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -687,6 +687,20 @@ m4_defun([AS_UNSET],
 ## ------------------------------------------ ##


+# _AS_INVOCATION
+# --------------
+# Set $as_invocation to a quoted representation of '$ $0 $@' that can be
+# pasted into a shell command line to achieve the same invocation.
+m4_define([_AS_INVOCATION],
+[as_invocation='$'
+for as_arg in "$[0]" "address@hidden"; do
+  case $as_arg in #((
+    *\'*) as_arg=\'`printf %s "$as_arg" | sed "s/'/'\\\\\\\\''/g"`\' ;;
+    '' | *[[!a-zA-Z0-9_.,:/+-]]*) as_arg=\'$as_arg\' ;;
+  esac
+  AS_VAR_APPEND([as_invocation], [" $as_arg"])
+done])
+
 # AS_MESSAGE_FD
 # -------------
 # Must expand to the fd where messages will be sent.  Defaults to 1,
diff --git a/tests/m4sh.at b/tests/m4sh.at
index c18cdcf..ff4f20f 100644
--- a/tests/m4sh.at
+++ b/tests/m4sh.at
@@ -1959,3 +1959,26 @@ AT_CHECK([$CONFIG_SHELL ./script], [], [foobar
 ])

 AT_CLEANUP
+
+
+## ---------------- ##
+## _AS_INVOCATION.  ##
+## ---------------- ##
+
+AT_SETUP([_AS@&address@hidden)
+
+AT_DATA_M4SH([script.as], [[dnl
+AS_INIT
+_AS_PREPARE
+_AS_INVOCATION
+echo "$as_invocation"
+]])
+
+AT_CHECK_M4SH
+AT_CHECK([$CONFIG_SHELL ./script], [], [$ ./script
+])
+AT_CHECK([$CONFIG_SHELL ./script a.1 "b  c" "d'e" 'f"g"' "" "#" "*" h=i],
+         [], [$ ./script a.1 'b  c' 'd'\''e' 'f"g"' '' '#' '*' 'h=i'
+])
+
+AT_CLEANUP
-- 
2.9.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]