Hello,
  this patch contains various slight optimizations.
When you use expr instead of echo|sed, you save 2 processes.

Paul, do you see any problem here?

Stepan
2005-04-29  Stepan Kasal  <[EMAIL PROTECTED]>

        * lib/autoconf/general.m4 (_AC_INIT_HELP): Merge several smaller
          ``cat <<_ACEOF'' commands to one.
        (_AC_CANONICAL_SPLIT): Use expr, not ``echo|sed.''
        * lib/autoconf/status.m4: On various places, use expr instead of
          ``echo|sed.''
        (_AC_CONFIG_SPLIT, _AC_CONFIG_SPLIT_SOURCE_DEST):
        (_AC_CONFIG_SPLIT_FILE_IN): New macros, to factor out common code.
        * lib/autotest/general.m4 (AT_INIT): Use expr to get the numbers from
          a range.
        * tests/local.at (AT_CHECK_SHELL_SYNTAX): Use awk to search for
          the wrong patterns between ``case'' and ``esac.''  The previous
          code had false positives.

Index: lib/autoconf/general.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/general.m4,v
retrieving revision 1.851
diff -u -r1.851 general.m4
--- lib/autoconf/general.m4     20 Apr 2005 05:34:25 -0000      1.851
+++ lib/autoconf/general.m4     29 Apr 2005 16:23:18 -0000
@@ -1013,9 +1013,6 @@
   -n, --no-create         do not create output files
       --srcdir=DIR        find the sources in DIR [configure dir or \`..']
 
-_ACEOF
-
-  cat <<_ACEOF
 Installation directories:
   --prefix=PREFIX         install architecture-independent files in PREFIX
                          [$ac_default_prefix]
@@ -1049,9 +1046,7 @@
   --dvidir=DIR           dvi documentation [DOCDIR]
   --pdfdir=DIR           pdf documentation [DOCDIR]
   --psdir=DIR            ps documentation [DOCDIR]
-_ACEOF
-
-  cat <<\_ACEOF]
+]dnl
 m4_divert_pop([HELP_BEGIN])dnl
 dnl The order of the diversions here is
 dnl - HELP_BEGIN
@@ -1694,12 +1689,9 @@
 m4_define([_AC_CANONICAL_SPLIT],
 [AC_SUBST([$1],       [$ac_cv_$1])dnl
 dnl FIXME: AC_SUBST([$1_alias],  [$ac_cv_$1_alias])dnl
-AC_SUBST([$1_cpu],
-        [`echo $ac_cv_$1 | sed 's/^\([[^-]]*\)-\([[^-]]*\)-\(.*\)$/\1/'`])dnl
-AC_SUBST([$1_vendor],
-        [`echo $ac_cv_$1 | sed 's/^\([[^-]]*\)-\([[^-]]*\)-\(.*\)$/\2/'`])dnl
-AC_SUBST([$1_os],
-        [`echo $ac_cv_$1 | sed 's/^\([[^-]]*\)-\([[^-]]*\)-\(.*\)$/\3/'`])dnl
+AC_SUBST([$1_cpu],     [`expr "X$ac_cv_$1" : ['X\([^-]*\)']`])dnl
+AC_SUBST([$1_vendor],  [`expr "X$ac_cv_$1" : ['X[^-]*-\([^-]*\)']`])dnl
+AC_SUBST([$1_os],      [`expr "X$ac_cv_$1" : ['X[^-]*-[^-]*-\(.*\)']`])dnl
 ])# _AC_CANONICAL_SPLIT
 
 
Index: lib/autoconf/status.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/status.m4,v
retrieving revision 1.52
diff -u -r1.52 status.m4
--- lib/autoconf/status.m4      27 Apr 2005 10:04:36 -0000      1.52
+++ lib/autoconf/status.m4      29 Apr 2005 16:23:18 -0000
@@ -151,7 +151,7 @@
     if test -z "$ac_top_builddir"; then
        ac_top_srcdir=.
     else
-       ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
+       ac_top_srcdir=`expr "X$ac_top_builddir" : ['X\(.*[^/]\)']`
     fi ;;
   [[\\/]]* | ?:[[\\/]]* )  # Absolute name.
     ac_srcdir=$srcdir$ac_dir_suffix;
@@ -245,6 +245,44 @@
 ])
 
 
+# _AC_CONFIG_SPLIT(LIST, DEST, SOURCE)
+# ------------------------------------
+#
+# Shell variable LIST must contain at least two file names, separated by
+# colon.  The first component goes to DEST, the rest to SOURCE.
+# We compute SOURCE first, so LIST and DEST can be the same variable.
+#
+m4_define([_AC_CONFIG_SPLIT],
+[      $3=`expr "X$$1" : ['X[^:]*:\(.*\)']`
+       $2=`expr "X$$1" : ['X\([^:]*\)']`[]dnl
+])
+
+# _AC_CONFIG_SPLIT_SOURCE_DEST
+# ----------------------------
+#
+# Used in CONFIG_COMMANDS and CONFIG_LIST sections.
+#
+m4_define([_AC_CONFIG_SPLIT_SOURCE_DEST],
+[case $ac_file in
+  *:*) _AC_CONFIG_SPLIT(ac_file, ac_dest, ac_source) ;;
+  *)   ac_dest=$ac_file ac_source=$ac_file ;;
+esac[]dnl
+])
+
+# _AC_CONFIG_SPLIT_FILE_IN
+# ------------------------
+#
+# Used in CONFIG_COMMANDS and CONFIG_LIST sections.
+#
+m4_define([_AC_CONFIG_SPLIT_FILE_IN],
+[case $ac_file in
+  *:*) _AC_CONFIG_SPLIT(ac_file, ac_file, ac_file_in) ;;
+  - )  ac_file_in=- ;;
+  * )   ac_file_in=$ac_file.in ;;
+esac[]dnl
+])
+
+
 
 ## ------------------------ ##
 ## Configuration commands.  ##
@@ -365,8 +403,7 @@
 # CONFIG_COMMANDS section.
 #
 for ac_file in : $CONFIG_COMMANDS; do test "x$ac_file" = x: && continue
-  ac_dest=`echo "$ac_file" | sed 's,:.*,,'`
-  ac_source=`echo "$ac_file" | sed 's,[[^:]]*:,,'`
+  _AC_CONFIG_SPLIT_SOURCE_DEST
   ac_dir=`AS_DIRNAME(["$ac_dest"])`
   AS_MKDIR_P(["$ac_dir"])
   _AC_SRCDIRS(["$ac_dir"])
@@ -507,13 +544,9 @@
   # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
   case $ac_file in
   - | *:- | *:-:* ) # input from stdin
-       cat >"$tmp/stdin"
-       ac_file_in=`echo "$ac_file" | sed 's,[[^:]]*:,,'`
-       ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
-  *:* ) ac_file_in=`echo "$ac_file" | sed 's,[[^:]]*:,,'`
-       ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
-  * )   ac_file_in=$ac_file.in ;;
+       cat >"$tmp/stdin" ;;
   esac
+  _AC_CONFIG_SPLIT_FILE_IN
 
   test x"$ac_file" != x- && AC_MSG_NOTICE([creating $ac_file])
 
@@ -729,7 +762,7 @@
 # interest in creating config links with literal values, no special
 # mechanism is implemented to handle them.
 #
-# _AC_LINK_CNT is used to be robust to multiple calls.
+# _AC_LINK_FILES_CNT is used to be robust to multiple calls.
 AU_DEFUN([AC_LINK_FILES],
 [m4_if($#, 2, ,
        [m4_fatal([$0: incorrect number of arguments])])dnl
@@ -768,8 +801,7 @@
 dnl with empty parameters (as in gettext.m4), then we obtain here
 dnl `:', which we want to skip.  So let's keep a single exception: `:'.
 for ac_file in : $CONFIG_LINKS; do test "x$ac_file" = x: && continue
-  ac_dest=`echo "$ac_file" | sed 's,:.*,,'`
-  ac_source=`echo "$ac_file" | sed 's,[[^:]]*:,,'`
+  _AC_CONFIG_SPLIT_SOURCE_DEST
 
   AC_MSG_NOTICE([linking $srcdir/$ac_source to $ac_dest])
 
@@ -934,13 +966,9 @@
   # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
   case $ac_file in
   - | *:- | *:-:* ) # input from stdin
-       cat >"$tmp/stdin"
-       ac_file_in=`echo "$ac_file" | sed 's,[[^:]]*:,,'`
-       ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
-  *:* ) ac_file_in=`echo "$ac_file" | sed 's,[[^:]]*:,,'`
-       ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
-  * )   ac_file_in=$ac_file.in ;;
+       cat >"$tmp/stdin" ;;
   esac
+  _AC_CONFIG_SPLIT_FILE_IN
 
   # Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories.
   ac_dir=`AS_DIRNAME(["$ac_file"])`
@@ -1407,8 +1435,8 @@
 do
   case $[1] in
   --*=*)
-    ac_option=`expr "x$[1]" : 'x\([[^=]]*\)='`
-    ac_optarg=`expr "x$[1]" : 'x[[^=]]*=\(.*\)'`
+    ac_option=`expr "X$[1]" : 'X\([[^=]]*\)='`
+    ac_optarg=`expr "X$[1]" : 'X[[^=]]*=\(.*\)'`
     ac_shift=:
     ;;
   -*)
Index: lib/autotest/general.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autotest/general.m4,v
retrieving revision 1.175
diff -u -r1.175 general.m4
--- lib/autotest/general.m4     4 Apr 2005 10:19:10 -0000       1.175
+++ lib/autotest/general.m4     29 Apr 2005 16:23:18 -0000
@@ -320,8 +320,9 @@
     [[0-9][0-9][0-9]-[0-9][0-9][0-9]] | \
     [[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] | \
     [[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] )
-       at_range_start=`echo $at_option |sed 's,-.*,,'`
-       at_range_end=`echo $at_option |sed 's,.*-,,'`
+       # No need to use "X$at_option", we know how $at_option looks like.
+       at_range_start=`expr $at_option : '\([^-]*\)'`
+       at_range_end=`expr $at_option : '[^-]*-\(.*\)'`
        # FIXME: Maybe test to make sure start <= end?
        at_range=`echo " $at_groups_all " | \
          sed -e 's,^.* '$at_range_start' ,'$at_range_start' ,' \
Index: tests/local.at
===================================================================
RCS file: /cvsroot/autoconf/autoconf/tests/local.at,v
retrieving revision 1.13
diff -u -r1.13 local.at
--- tests/local.at      5 Feb 2005 07:58:43 -0000       1.13
+++ tests/local.at      29 Apr 2005 16:23:18 -0000
@@ -53,7 +53,7 @@
 m4_define([AT_CHECK_SHELL_SYNTAX],
 [AS_IF([test x"$ac_cv_sh_n_works" != xno],
   [AT_CHECK([/bin/sh -n $1], 0)], [$2])
-AT_CHECK([grep '\@<:@\^.*).*;;' $1], 1)])
+AT_CHECK([awk '/^[ \t]*case/,/^[ \t]*esac/{if(/\@<:@\^.*\)/) exit(1)}' $1])])
 
 m4_define([AT_CHECK_PERL_SYNTAX],
 [AT_CHECK([autom4te_perllibdir=$abs_top_srcdir/lib $PERL -c 
$abs_top_builddir/bin/$1],

Reply via email to