>From 0ce63a38ab7c87502504ba7d2319886d4f4a7d15 Mon Sep 17 00:00:00 2001 Message-Id: From: Stefano Lattarini Date: Wed, 16 May 2012 17:35:05 +0200 Subject: [PATCH 1/2] ylwrap: preparatory refactoring This commit should cause no semantic change in the ylwrap behaviour. It will only be needed in light of a future change. See: * lib/ylwrap (get_dirname, quote_for_sed): New functions, factoring out some non-trivial code. Use them where appropriate. Signed-off-by: Stefano Lattarini --- lib/ylwrap | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/ylwrap b/lib/ylwrap index 36543da..8a20288 100755 --- a/lib/ylwrap +++ b/lib/ylwrap @@ -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" -- 1.7.9.5