]> git.draconx.ca Git - dxcommon.git/commitdiff
Fix DX_COMMAND_OUTPUT backslash-newline on heirloom-sh.
authorNick Bowler <nbowler@draconx.ca>
Tue, 9 Mar 2021 03:36:50 +0000 (22:36 -0500)
committerNick Bowler <nbowler@draconx.ca>
Tue, 9 Mar 2021 03:36:50 +0000 (22:36 -0500)
It seems that heirloom-sh (and presumably Solaris /bin/sh) read just
silently eats backslash-newlines, and escaping the backslash does
nothing useful, the shell just eats both backslashes and the newline.

Attempt to avoid this problem by appending a magic string to
troublesome lines, and stripping it after reading.  This will
obviously fail if the input _actually_ has this sequence but
hopefully that will not be an issue in practice.

m4/cmdout.m4

index 90aa13ea0c361e2d985add8b11547e29acdd46dd..c91aca1057ec131be2c179dc7ffa1facd99c29b4 100644 (file)
@@ -22,12 +22,19 @@ AC_DEFUN_ONCE([_DX_COMMAND_OUTPUT_SETUP], [m4_divert_push([INIT_PREPARE])dnl
 dx_fn_cmdout_collect_output () {
   AS_UNSET([$][1])
   # Double up backslashes as they will be stripped by read.
 dx_fn_cmdout_collect_output () {
   AS_UNSET([$][1])
   # Double up backslashes as they will be stripped by read.
-  sed 's/\\/\\\\/g' conftest.do0 >conftest.do1 || return
+  # Heirloom sh read apparently just eats backslashes at EOL, so we compromise
+  # by adding a marker that can be stripped out afterwards.
+  _dx_eol='@%eol@%'
+  sed -e 's/\\/\\\\/g' -e 's/\\$/\\'"$_dx_eol/" conftest.do0 >conftest.do1 ||
+    return
   exec 3<conftest.do1
   _dx_save_IFS=$IFS
   exec 3<conftest.do1
   _dx_save_IFS=$IFS
-  IFS=
-  while read _dx_tmp <&3
+  while IFS=; read _dx_tmp <&3
   do
   do
+    IFS=$_dx_save_IFS
+    # strip out EOL marker, if present
+    AS_CASE([$_dx_tmp], [*"\\$_dx_eol"],
+      [_dx_tmp=`AS_ECHO(["$_dx_tmp"]) | sed "s/$_dx_eol\$//"`])
     AS_VAR_SET_IF([$][1],
       [AS_VAR_APPEND([$][1], ["$as_nl$_dx_tmp"])],
       [AS_VAR_SET([$][1], [$_dx_tmp])])
     AS_VAR_SET_IF([$][1],
       [AS_VAR_APPEND([$][1], ["$as_nl$_dx_tmp"])],
       [AS_VAR_SET([$][1], [$_dx_tmp])])