ylwrap: preparatory refactoring
authorStefano Lattarini <stefano.lattarini@gmail.com>
Wed, 16 May 2012 15:35:05 +0000 (17:35 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Wed, 16 May 2012 16:06:27 +0000 (18:06 +0200)
This commit should cause no semantic change in the ylwrap behaviour.
It will only be needed in light of a future change.  See:
<http://lists.gnu.org/archive/html/automake/2012-05/msg00013.html>

* lib/ylwrap (get_dirname, quote_for_sed): New functions, factoring
out some non-trivial code.  Use them where appropriate.

Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
lib/ylwrap

index 36543da..8a20288 100755 (executable)
@@ -62,6 +62,19 @@ EOF
     ;;
 esac
 
+get_dirname ()
+{
+  case $1 in
+    */*|*\\*) printf '%s\n' "$1" | sed -e 's,\([\\/]\)[^\\/]*$,\1,';;
+    # Otherwise,  we want the empty string (not ".").
+  esac
+}
+
+quote_for_sed ()
+{
+  # FIXME: really we should care about more than '.' and '\'.
+  sed -e 's,[\\.],\\&,g'
+}
 
 # The input.
 input="$1"
@@ -125,11 +138,7 @@ if test $ret -eq 0; then
     y_tab_nodot="yes"
   fi
 
-  # The directory holding the input.
-  input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'`
-  # Quote $INPUT_DIR so we can use it in a regexp.
-  # FIXME: really we should care about more than '.' and '\'.
-  input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'`
+  input_rx=`get_dirname "$input" | quote_for_sed`
 
   while test "$#" -ne 0; do
     from="$1"