From: Stefano Lattarini Date: Wed, 16 May 2012 15:35:05 +0000 (+0200) Subject: ylwrap: preparatory refactoring X-Git-Tag: v1.12.0b~2^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0ce63a38ab7c87502504ba7d2319886d4f4a7d15;p=platform%2Fupstream%2Fautomake.git 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 --- 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"