[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Portable use of "{", ";", etc. within sed scripts
From: |
Paul Eggert |
Subject: |
Re: Portable use of "{", ";", etc. within sed scripts |
Date: |
Thu, 05 Jan 2006 16:02:27 -0800 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) |
Noah Misch <address@hidden> writes:
> You introduced the `s|a|b|' convention to much of Autoconf in a change dated
> 2005-03-22, to support file names containing `,'. The `s,a,b,' recommendation
> in the manual predates that change. Is `s,a,b' preferable after all, or is it
> the manual's recommendation that should change?
Ouch. Good catch. I reverted that part of the change, found some
more instances where Autoconf should be tasting its own medicine, and
installed the following.
2006-01-05 Paul Eggert <address@hidden>
* Makefile.maint (sc_root_tests): Use recommend style s/a/b/ for
sed substitutions.
* doc/autoconf.texi (Installation Directory Variables): Use s|a|b|
for file names, again. Reported by Noah Misch.
(Coding Style): Explain that s|a|b| is preferred for file names.
* lib/autoconf/status.m4 (_AC_OUTPUT_FILES_PREPARE): Prefer s/a/b/.
(AC_OUTPUT_MAKE_DEFS): Likewise.
* lib/autotest/general.m4 (AT_INIT): Likewise.
* lib/m4sugar/m4sh.m4 (_AS_LINENO_PREPARE): Likewise.
* tests/local.at (AT_CHECK_AUTOM4TE): Likewise.
Index: Makefile.maint
===================================================================
RCS file: /cvsroot/autoconf/autoconf/Makefile.maint,v
retrieving revision 1.32
diff -p -u -r1.32 Makefile.maint
--- Makefile.maint 23 Aug 2005 07:46:54 -0000 1.32
+++ Makefile.maint 6 Jan 2006 00:00:58 -0000
@@ -2,7 +2,8 @@
# This Makefile fragment is shared between the coreutils,
# CPPI, Bison, and Autoconf.
-## Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+## Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software
+## Foundation, Inc.
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
@@ -207,7 +208,7 @@ sc_prohibit_jm_in_m4:
sc_root_tests:
@t1=sc-root.expected; t2=sc-root.actual; \
grep -nl '^PRIV_CHECK_ARG=require-root' \
- $$($(CVS_LIST) tests) |sed s,tests,., |sort > $$t1; \
+ $$($(CVS_LIST) tests) |sed s/tests/./ |sort > $$t1; \
sed -n 's, cd \([^ ]*\) .*MAKE..check TESTS=\(.*\),./\1/\2,p' \
$(srcdir)/tests/Makefile.am |sort > $$t2; \
diff -u $$t1 $$t2 || diff=1; \
Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.940
diff -p -u -r1.940 autoconf.texi
--- doc/autoconf.texi 5 Jan 2006 21:43:45 -0000 1.940
+++ doc/autoconf.texi 6 Jan 2006 00:00:59 -0000
@@ -2458,8 +2458,8 @@ Makefile snippet similar to:
@example
@group
edit = sed \
- -e 's,@@datadir[@@],$(pkgdatadir),g' \
- -e 's,@@prefix[@@],$(prefix),g'
+ -e 's|@@datadir[@@]|$(pkgdatadir)|g' \
+ -e 's|@@prefix[@@]|$(prefix)|g'
@end group
@group
@@ -9621,7 +9621,13 @@ better than hacking Autoconf @code{:-)}.
When using @command{sed}, don't use @option{-e} except for indenting
purposes. With the @code{s} and @code{y} commands, the preferred
separator is @samp{/} unless @samp{/} itself might appear in the pattern
-or replacement, in which case you should use @samp{,}.
+or replacement, in which case you should use @samp{|}, or optionally
address@hidden,} if you know the pattern and replacement cannot contain a file
+name. If none of these characters will do, choose a printable character
+that cannot appear in the pattern or replacement. Characters from the
+set @samp{"#$&'()*;<=>?`|~} are good choices if the pattern or
+replacement might contain a file name, since they have special meaning
+to the shell and are less likely to occur in file names.
@xref{Macro Definitions}, for details on how to define a macro. If a
macro doesn't use @code{AC_REQUIRE} and it is expected to never be the
Index: lib/autoconf/status.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/status.m4,v
retrieving revision 1.82
diff -p -u -r1.82 status.m4
--- lib/autoconf/status.m4 5 Jan 2006 21:43:45 -0000 1.82
+++ lib/autoconf/status.m4 6 Jan 2006 00:00:59 -0000
@@ -389,7 +389,7 @@ m4_if(_AC_Var, [ac_delim],
[dnl Just to be on the safe side, claim that $ac_delim is the empty string.
m4_define([_AC_SED_FRAG],
m4_defn([_AC_SED_FRAG])dnl
-[s,ac_delim,|#_!!_#|,g
+[s/ac_delim/|#_!!_#|/g
])dnl
m4_define([_AC_SED_CMD_NUM], m4_incr(_AC_SED_CMD_NUM))],
_AC_Var, address@hidden@],
@@ -1435,16 +1435,16 @@ m4_define([AC_OUTPUT_MAKE_DEFS],
cat >confdef2opt.sed <<\_ACEOF
t clear
:clear
-s,^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[
]*\(.*\),-D\1=\2,g
+s/^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[
]*\(.*\)/-D\1=\2/g
t quote
-s,^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[
]*\(.*\),-D\1=\2,g
+s/^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[
]*\(.*\)/-D\1=\2/g
t quote
d
:quote
-s,[ `~#$^&*(){}\\|;'"<>?],\\&,g
-s,\[,\\&,g
-s,\],\\&,g
-s,\$,$$,g
+s/[ `~#$^&*(){}\\|;'"<>?]/\\&/g
+s/\[/\\&/g
+s/\]/\\&/g
+s/\$/$$/g
p
_ACEOF
# We use echo to avoid assuming a particular line-breaking character.
Index: lib/autotest/general.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autotest/general.m4,v
retrieving revision 1.193
diff -p -u -r1.193 general.m4
--- lib/autotest/general.m4 4 Oct 2005 09:14:12 -0000 1.193
+++ lib/autotest/general.m4 6 Jan 2006 00:00:59 -0000
@@ -1,7 +1,7 @@
# This file is part of Autoconf. -*- Autoconf -*-
# M4 macros used in building test suites.
-# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software
+# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
# Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
@@ -306,14 +306,14 @@ do
[[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 |tr -d '-'`
at_range=`echo " $at_groups_all " | \
- sed -e 's,^.* \('$at_range_start' \),\1,'`
+ sed -e 's/^.* \('$at_range_start' \)/\1/'`
at_groups="$at_groups$at_range "
;;
[-[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9] | -[0-9][0-9][0-9][0-9]])
at_range_end=`echo $at_option |tr -d '-'`
at_range=`echo " $at_groups_all " | \
- sed -e 's,\( '$at_range_end'\) .*$,\1,'`
+ sed -e 's/\( '$at_range_end'\) .*$/\1/'`
at_groups="$at_groups$at_range "
;;
@@ -331,8 +331,8 @@ do
at_range_start=$at_tmp
fi
at_range=`echo " $at_groups_all " | \
- sed -e 's,^.*\( '$at_range_start' \),\1,' \
- -e 's,\( '$at_range_end'\) .*$,\1,'`
+ sed -e 's/^.*\( '$at_range_start' \)/\1/' \
+ -e 's/\( '$at_range_end'\) .*$/\1/'`
at_groups="$at_groups$at_range "
;;
Index: lib/m4sugar/m4sh.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/m4sugar/m4sh.m4,v
retrieving revision 1.153
diff -p -u -r1.153 m4sh.m4
--- lib/m4sugar/m4sh.m4 5 Jan 2006 21:43:45 -0000 1.153
+++ lib/m4sugar/m4sh.m4 6 Jan 2006 00:00:59 -0000
@@ -773,15 +773,15 @@ _AS_LINENO_WORKS || {
/[[$]]LINENO/=
' <$as_myself |
sed '
- s,[[$]]LINENO.*,&-,
+ s/[[$]]LINENO.*/&-/
t lineno
b
:lineno
N
:loop
- s,[[$]]LINENO\([[^'$as_cr_alnum'_]].*\n\)\(.*\),\2\1\2,
+ s/[[$]]LINENO\([[^'$as_cr_alnum'_]].*\n\)\(.*\)/\2\1\2/
t loop
- s,-\n.*,,
+ s/-\n.*//
' >$as_me.lineno &&
chmod +x $as_me.lineno ||
AS_ERROR([cannot create $as_me.lineno; rerun with a POSIX shell])
Index: tests/local.at
===================================================================
RCS file: /cvsroot/autoconf/autoconf/tests/local.at,v
retrieving revision 1.23
diff -p -u -r1.23 local.at
--- tests/local.at 9 Dec 2005 09:54:12 -0000 1.23
+++ tests/local.at 6 Jan 2006 00:00:59 -0000
@@ -1,6 +1,6 @@
# M4 macros used in building Autoconf test suites. -*- Autotest -*-
-# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software
+# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
# Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
@@ -91,8 +91,8 @@ m4_define([AT_CHECK_PERL_SYNTAX],
m4_define([AT_CHECK_AUTOM4TE],
[AT_CHECK([autom4te $1], [$2], [$3], m4_ifval([$4], [stderr]))
m4_ifval([$4],
-[AT_CHECK([[sed -e 's,^\([^:]*\): *\([0-9][0-9]*\): *[^:]*m4: ,m4: \1: \2: ,' \
- -e 's,^[^:]*m4: *\([^:]*\): *\([0-9][0-9]*\): ,m4: \1: \2: ,' \
+[AT_CHECK([[sed -e 's/^\([^:]*\): *\([0-9][0-9]*\): *[^:]*m4: /m4: \1: \2: /' \
+ -e 's/^[^:]*m4: *\([^:]*\): *\([0-9][0-9]*\): /m4: \1: \2: /' \
-e 's/^autom4te: [^ ]*m4 /autom4te: m4 /' \
-e 's/^autom4te: [^ ]*m4.exe /autom4te: m4 /' \
-e 's/ (E[A-Z]*)$//' \