Source-Changes-HG archive

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

[src/trunk]: src Synchronise several shell_quote implementations, and:



details:   https://anonhg.NetBSD.org/src/rev/57a53d4c461c
branches:  trunk
changeset: 797943:57a53d4c461c
user:      apb <apb%NetBSD.org@localhost>
date:      Mon Aug 04 21:56:30 2014 +0000

description:
Synchronise several shell_quote implementations, and:
* Elide some unnecessary pairs of quotation marks, to improve readability.
  For example, shell_quote "''" is now \'\' instead of ''\'''\'''.
* Don't add quotes around words that contain only safe characters,
  to improve readability.
* LC_COLLATE=C to prevent [a-zA-Z] from matching non-ASCII characters.
* Use ${SED} if defined.

diffstat:

 build.sh                          |  46 ++++++++++++++++++++++++++++----------
 share/zoneinfo/tzdata2netbsd      |  26 ++++++++++++++++-----
 usr.bin/locate/locate/updatedb.sh |  43 +++++++++++++++++++++++++++---------
 usr.sbin/etcupdate/etcupdate      |  44 +++++++++++++++++++++++++++---------
 usr.sbin/postinstall/postinstall  |  44 +++++++++++++++++++++++++++---------
 5 files changed, 152 insertions(+), 51 deletions(-)

diffs (truncated from 324 to 300 lines):

diff -r c94d83205f6f -r 57a53d4c461c build.sh
--- a/build.sh  Mon Aug 04 21:41:44 2014 +0000
+++ b/build.sh  Mon Aug 04 21:56:30 2014 +0000
@@ -1,5 +1,5 @@
 #! /usr/bin/env sh
-#      $NetBSD: build.sh,v 1.288 2014/08/03 17:11:44 riz Exp $
+#      $NetBSD: build.sh,v 1.289 2014/08/04 21:56:30 apb Exp $
 #
 # Copyright (c) 2001-2011 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -286,21 +286,43 @@
 #    eval "set -- $quotedlist"
 # or like this:
 #    eval "\$command $quotedlist \$filename"
+#
 shell_quote()
-{
+{(
        local result=''
-       local arg
+       local arg qarg
+       LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII
        for arg in "$@" ; do
-               # Append a space if necessary
-               result="${result}${result:+ }"
-               # Convert each embedded ' to '\'',
-               # then insert ' at the beginning of the first line,
-               # and append ' at the end of the last line.
-               result="${result}$(printf "%s\n" "$arg" | \
-                       sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")"
+               case "${arg}" in
+               '')
+                       qarg="''"
+                       ;;
+               *[!-./a-zA-Z0-9]*)
+                       # Convert each embedded ' to '\'',
+                       # then insert ' at the beginning of the first line,
+                       # and append ' at the end of the last line.
+                       # Finally, elide unnecessary '' pairs at the
+                       # beginning and end of the result and as part of
+                       # '\'''\'' sequences that result from multiple
+                       # adjacent quotes in he input.
+                       qarg="$(printf "%s\n" "$arg" | \
+                           ${SED:-sed} -e "s/'/'\\\\''/g" \
+                               -e "1s/^/'/" -e "\$s/\$/'/" \
+                               -e "1s/^''//" -e "\$s/''\$//" \
+                               -e "s/'''/'/g"
+                               )"
+                       ;;
+               *)
+                       # Arg is not the empty string, and does not contain
+                       # any unsafe characters.  Leave it unchanged for
+                       # readability.
+                       qarg="${arg}"
+                       ;;
+               esac
+               result="${result}${result:+ }${qarg}"
        done
        printf "%s\n" "$result"
-}
+)}
 
 statusmsg()
 {
@@ -1774,7 +1796,7 @@
        eval cat <<EOF ${makewrapout}
 #! ${HOST_SH}
 # Set proper variables to allow easy "make" building of a NetBSD subtree.
-# Generated from:  \$NetBSD: build.sh,v 1.288 2014/08/03 17:11:44 riz Exp $
+# Generated from:  \$NetBSD: build.sh,v 1.289 2014/08/04 21:56:30 apb Exp $
 # with these arguments: ${_args}
 #
 
diff -r c94d83205f6f -r 57a53d4c461c share/zoneinfo/tzdata2netbsd
--- a/share/zoneinfo/tzdata2netbsd      Mon Aug 04 21:41:44 2014 +0000
+++ b/share/zoneinfo/tzdata2netbsd      Mon Aug 04 21:56:30 2014 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: tzdata2netbsd,v 1.3 2014/06/13 19:56:19 apb Exp $
+# $NetBSD: tzdata2netbsd,v 1.4 2014/08/04 21:56:30 apb Exp $
 
 # For use by NetBSD developers when updating to new versions of tzdata.
 #
@@ -75,29 +75,43 @@
 #    eval "set -- $quotedlist"
 # or like this:
 #    eval "\$command $quotedlist \$filename"
+#
 shell_quote()
-{
+{(
        local result=''
        local arg qarg
+       LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII
        for arg in "$@" ; do
                case "${arg}" in
-               ''|*[!-./a-zA-Z0-9]*)
+               '')
+                       qarg="''"
+                       ;;
+               *[!-./a-zA-Z0-9]*)
                        # Convert each embedded ' to '\'',
                        # then insert ' at the beginning of the first line,
                        # and append ' at the end of the last line.
+                       # Finally, elide unnecessary '' pairs at the
+                       # beginning and end of the result and as part of
+                       # '\'''\'' sequences that result from multiple
+                       # adjacent quotes in he input.
                        qarg="$(printf "%s\n" "$arg" | \
-                           sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")"
+                           ${SED:-sed} -e "s/'/'\\\\''/g" \
+                               -e "1s/^/'/" -e "\$s/\$/'/" \
+                               -e "1s/^''//" -e "\$s/''\$//" \
+                               -e "s/'''/'/g"
+                               )"
                        ;;
                *)
                        # Arg is not the empty string, and does not contain
-                       # any unsafe characters.
+                       # any unsafe characters.  Leave it unchanged for
+                       # readability.
                        qarg="${arg}"
                        ;;
                esac
                result="${result}${result:+ }${qarg}"
        done
        printf "%s\n" "$result"
-}
+)}
 
 findcvsroot()
 {
diff -r c94d83205f6f -r 57a53d4c461c usr.bin/locate/locate/updatedb.sh
--- a/usr.bin/locate/locate/updatedb.sh Mon Aug 04 21:41:44 2014 +0000
+++ b/usr.bin/locate/locate/updatedb.sh Mon Aug 04 21:56:30 2014 +0000
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-#      $NetBSD: updatedb.sh,v 1.14 2011/07/13 07:58:35 apb Exp $
+#      $NetBSD: updatedb.sh,v 1.15 2014/08/04 21:56:30 apb Exp $
 #
 # Copyright (c) 1989, 1993
 #      The Regents of the University of California.  All rights reserved.
@@ -61,20 +61,41 @@
 #    eval "\$command $quotedlist \$filename"
 #
 shell_quote()
-{
+{(
        local result=''
-       local arg
+       local arg qarg
+       LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII
        for arg in "$@" ; do
-               # Append a space if necessary
-               result="${result}${result:+ }"
-               # Convert each embedded ' to '\'',
-               # then insert ' at the beginning of the first line,
-               # and append ' at the end of the last line.
-               result="${result}$(printf "%s\n" "$arg" | \
-                       sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")"
+               case "${arg}" in
+               '')
+                       qarg="''"
+                       ;;
+               *[!-./a-zA-Z0-9]*)
+                       # Convert each embedded ' to '\'',
+                       # then insert ' at the beginning of the first line,
+                       # and append ' at the end of the last line.
+                       # Finally, elide unnecessary '' pairs at the
+                       # beginning and end of the result and as part of
+                       # '\'''\'' sequences that result from multiple
+                       # adjacent quotes in he input.
+                       qarg="$(printf "%s\n" "$arg" | \
+                           ${SED:-sed} -e "s/'/'\\\\''/g" \
+                               -e "1s/^/'/" -e "\$s/\$/'/" \
+                               -e "1s/^''//" -e "\$s/''\$//" \
+                               -e "s/'''/'/g"
+                               )"
+                       ;;
+               *)
+                       # Arg is not the empty string, and does not contain
+                       # any unsafe characters.  Leave it unchanged for
+                       # readability.
+                       qarg="${arg}"
+                       ;;
+               esac
+               result="${result}${result:+ }${qarg}"
        done
        printf "%s\n" "$result"
-}
+)}
 
 # read configuration file
 if [ -f "$CONF" ]; then
diff -r c94d83205f6f -r 57a53d4c461c usr.sbin/etcupdate/etcupdate
--- a/usr.sbin/etcupdate/etcupdate      Mon Aug 04 21:41:44 2014 +0000
+++ b/usr.sbin/etcupdate/etcupdate      Mon Aug 04 21:56:30 2014 +0000
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: etcupdate,v 1.57 2014/06/16 22:12:30 apb Exp $
+# $NetBSD: etcupdate,v 1.58 2014/08/04 21:56:30 apb Exp $
 #
 # Copyright (c) 2001-2008 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -138,21 +138,43 @@
 #    eval "set -- $quotedlist"
 # or like this:
 #    eval "\$command $quotedlist \$filename"
+#
 shell_quote()
-{
+{(
        local result=''
-       local arg
+       local arg qarg
+       LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII
        for arg in "$@" ; do
-               # Append a space if necessary
-               result="${result}${result:+ }"
-               # Convert each embedded ' to '\'',
-               # then insert ' at the beginning of the first line,
-               # and append ' at the end of the last line.
-               result="${result}$(printf "%s\n" "$arg" | \
-                       sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")"
+               case "${arg}" in
+               '')
+                       qarg="''"
+                       ;;
+               *[!-./a-zA-Z0-9]*)
+                       # Convert each embedded ' to '\'',
+                       # then insert ' at the beginning of the first line,
+                       # and append ' at the end of the last line.
+                       # Finally, elide unnecessary '' pairs at the
+                       # beginning and end of the result and as part of
+                       # '\'''\'' sequences that result from multiple
+                       # adjacent quotes in he input.
+                       qarg="$(printf "%s\n" "$arg" | \
+                           ${SED:-sed} -e "s/'/'\\\\''/g" \
+                               -e "1s/^/'/" -e "\$s/\$/'/" \
+                               -e "1s/^''//" -e "\$s/''\$//" \
+                               -e "s/'''/'/g"
+                               )"
+                       ;;
+               *)
+                       # Arg is not the empty string, and does not contain
+                       # any unsafe characters.  Leave it unchanged for
+                       # readability.
+                       qarg="${arg}"
+                       ;;
+               esac
+               result="${result}${result:+ }${qarg}"
        done
        printf "%s\n" "$result"
-}
+)}
 
 # Convert arg $1 to a basic regular expression (as in sed)
 # that will match the arg.  This works by inserting backslashes
diff -r c94d83205f6f -r 57a53d4c461c usr.sbin/postinstall/postinstall
--- a/usr.sbin/postinstall/postinstall  Mon Aug 04 21:41:44 2014 +0000
+++ b/usr.sbin/postinstall/postinstall  Mon Aug 04 21:56:30 2014 +0000
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: postinstall,v 1.174 2014/06/16 22:12:30 apb Exp $
+# $NetBSD: postinstall,v 1.175 2014/08/04 21:56:30 apb Exp $
 #
 # Copyright (c) 2002-2008 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -112,21 +112,43 @@
 #    eval "set -- $quotedlist"
 # or like this:
 #    eval "\$command $quotedlist \$filename"
+#
 shell_quote()
-{
+{(
        local result=''
-       local arg
+       local arg qarg
+       LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII
        for arg in "$@" ; do
-               # Append a space if necessary
-               result="${result}${result:+ }"
-               # Convert each embedded ' to '\'',
-               # then insert ' at the beginning of the first line,
-               # and append ' at the end of the last line.
-               result="${result}$(printf "%s\n" "$arg" | \
-                       ${SED} -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")"
+               case "${arg}" in
+               '')
+                       qarg="''"
+                       ;;
+               *[!-./a-zA-Z0-9]*)
+                       # Convert each embedded ' to '\'',
+                       # then insert ' at the beginning of the first line,
+                       # and append ' at the end of the last line.
+                       # Finally, elide unnecessary '' pairs at the
+                       # beginning and end of the result and as part of



Home | Main Index | Thread Index | Old Index