autoconf-patches
[Top][All Lists]
Advanced

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

AC_PROG_SED


From: Robert Boehne
Subject: AC_PROG_SED
Date: Mon, 07 Jan 2002 17:23:02 -0600

Hello,

This patch adds a macro that was developed for Libtool
to find a sed program that does not truncate its output,
or at least, truncates as little as possible.  It checks
the user's path for sed and gsed, then loops through
those found to select any GNU sed, and failing that
selects a sed that truncates as little output as possible,
then sets $SED to the one found.

ChangeLog entry:

2002-01-06  Robert Boehne  <address@hidden>
        Based on a post by Albert Chin <address@hidden>:

        * lib/autoconf/programs.m4 (AC_PROG_SED): Find a sed
        program that will not truncate its output.

-- 
Robert Boehne             Software Engineer
Ricardo Software   Chicago Technical Center
TEL: (630)789-0003 x. 238
FAX: (630)789-0127
email:  address@hidden
? ac_prog_sed.patch
Index: lib/autoconf/programs.m4
===================================================================
RCS file: /cvs/autoconf/lib/autoconf/programs.m4,v
retrieving revision 1.8
diff -u -r1.8 programs.m4
--- lib/autoconf/programs.m4    12 Nov 2001 16:08:53 -0000      1.8
+++ lib/autoconf/programs.m4    7 Jan 2002 23:12:38 -0000
@@ -459,6 +459,92 @@
 Remove this warning when you adjust the code.])])
 
 
+# AC_PROG_SED
+# --------------
+# Check for a fully-functional sed program, that truncates
+# as few characters as possible.  Prefer GNU sed if found.
+AC_DEFUN([AC_PROG_SED],
+[AC_MSG_CHECKING([for a sed that does not truncate output])
+if test "x$SED" != "x"; then
+  :
+else
+# Loop through the user's path and test -x for sed and gsed.
+# Then use that list of sed's as ones to test for truncation.
+  _sed_list=""
+  save_ifs="$IFS"; IFS=':'
+  for pat in $PATH; do
+    IFS="$save_ifs"
+    if test -x "$pat/sed"; then
+      _sed_list="$_sed_list $pat/sed"
+    fi
+    # Do the test twice in case sed and gsed are in
+    # the same directory.
+    if test -x "$pat/gsed"; then
+      _sed_list="$_sed_list $pat/gsed"
+    fi
+  done
+  IFS="$save_ifs"
+  trap "rm -f /tmp/$$-sed-out /tmp/$$-sed-in /tmp/$$-sed-in-nl /tmp/$$" 0 2 13
+  if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
+    if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
+      ac_n=
+      ac_c='
+'
+      ac_t='   '
+    else
+      ac_n=-n
+      ac_c=
+      ac_t=
+    fi
+  else
+    ac_n=
+    ac_c='\c'
+    ac_t=
+  fi
+  _max=0
+  _count=0
+  # Add /usr/xpg4/bin/sed as it is typically found on Solaris
+  # along with /bin/sed that truncates output.
+  for _sed in $_gsed $_sed_list /usr/xpg4/bin/sed; do
+    test ! -f ${_sed} && break
+    cp /dev/null /tmp/$$-sed-in
+    _count=0
+    echo $ac_n "0123456789$ac_c" >/tmp/$$-sed-in
+    # Check for GNU sed and select it if it is found.
+    if "${_sed}" --version 2>&1 < /dev/null | egrep '(GNU)' > /dev/null; then
+      _best_sed=${_sed}
+      break;
+    fi
+    while /bin/true; do
+      cat /tmp/$$-sed-in /tmp/$$-sed-in >/tmp/$$
+      mv /tmp/$$ /tmp/$$-sed-in
+      cp /tmp/$$-sed-in /tmp/$$-sed-in-nl
+      echo >>/tmp/$$-sed-in-nl
+      ${_sed} -e 's/a$//' < /tmp/$$-sed-in-nl >/tmp/$$-sed-out
+      test $? -ne 0 && break
+      cmp -s /tmp/$$-sed-out /tmp/$$-sed-in-nl
+      test $? -ne 0 && break
+      # 10000 chars as input seems more than enough
+      test $_count -gt 10 && break
+      _count=`expr $_count + 1`
+      if test $_count -gt $_max; then
+        _max=$_count
+        _best_sed=$_sed
+      fi
+    done
+  done
+  SED=$_best_sed
+fi
+if test ! -x $SED; then
+  # Error out if $SED is not executable.
+  AC_MSG_ERROR([cannot execute $SED.])
+fi
+AC_SUBST([SED])
+AC_MSG_RESULT([$SED])
+])
+# AC_PROG_SED
+
+
 # AC_PROG_YACC
 # ------------
 AC_DEFUN([AC_PROG_YACC],

reply via email to

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