From 564a3e2ec83e3883cafe9efd2c6f88144a0835db Mon Sep 17 00:00:00 2001 From: Einhard Leichtfuß Date: Sun, 23 Dec 2018 05:58:13 +0100 Subject: Simplify basic.sh:replace_line and switch to EREs EREs: extended regular expressions in contrast to basic regular expressions (BREs). --- TODO | 2 ++ basic.sh | 32 ++++++++++++++++++++------------ update.sh | 15 +-------------- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/TODO b/TODO index 42bec21..f4571d4 100644 --- a/TODO +++ b/TODO @@ -5,3 +5,5 @@ Notify on checksum change. Check for update of freedict-tools. Use updpkgsums from pacman-contrib. + +Increase pkgrel (to be made optional). diff --git a/basic.sh b/basic.sh index ed4a442..7740978 100644 --- a/basic.sh +++ b/basic.sh @@ -3,6 +3,8 @@ # Copyright 2018 Einhard Leichtfuß # +# All methods operate on the file "$tmp". + typeset -a langs langs=( fra-deu deu-fra @@ -31,37 +33,43 @@ function cleanup } trap cleanup EXIT -# $1: string to replace: regular expression +# $1: string to replace: extended regular expression # $2: string to replace with: sed replacement string function replace { - sed -i "s/${1}/${2}/g" "$tmp" + sed -Ei "s/${1}/${2}/g" "$tmp" } -# $1 line to replace: regular expression +# Replace line by a string (possibly including newlines). +# $1 line to replace: extended regular expression # $2 text to replace with: (newline terminated) sed replacement string # $3 removal type: (rm-plus-one|normal) +# `- If $2 is empty, whether to remove only that line or also the one +# following. function replace_line { if test -n "$2" then - cat <(sed "/${1}/,\$ d" < "$tmp") \ - <(echo -n "$2") \ - <(sed "0,/${1}/ d" < "$tmp") \ - > "$tmp_" - mv "$tmp_" "$tmp" + printf '%s' "$2" > "$tmp_" + + sed -Ei " + /${1}/ { + r $tmp_ + d + } + " "$tmp" else if [[ "$3" == rm-plus-one ]] then - sed -i "/${1}/,+1 d" "$tmp" + sed -Ei "/${1}/,+1 d" "$tmp" else - sed -i "/${1}/ d" "$tmp" + sed -Ei "/${1}/ d" "$tmp" fi fi } -# $1 line to delete: regular expression +# $1 line to delete: extended regular expression function delete_line { - sed -i "/${1}/ d" "$tmp" + sed -Ei "/${1}/ d" "$tmp" } diff --git a/update.sh b/update.sh index 503ee22..f1def66 100755 --- a/update.sh +++ b/update.sh @@ -33,25 +33,12 @@ prepare[deu-fra]=\ { cd $_lang sed -Ei \ - -e '"'"'s/(10)(10)(100\>)(.*(1|Eins) mit einem Googol Nullen)/\1^(\2^\3)\4/'"'"' \ + -e '"'"'s/(10)(10)(100\>)(\s+\(10)(Googol.*(1|Eins) mit einem Googol Nullen)/\1^(\2^\3)\4^\5/'"'"' \ -e '"'"'s/(10)([1-9][0-9]*)(.*(1|Eins) mit \2 Nullen)/\1\^\2\3/'"'"' \ -e '"'"'s/(die Zahl 10)(60)/\1^\2/'"'"' \ ${_lang}.tei } ' -prepare[deu-fra-bin]=\ -'prepare() -{ - cd $_lang - dictzip -d ${_lang}.dict.dz - sed -Ei \ - -e '"'"'s/(10)(10)(100\>)(.*(1|Eins) mit einem Googol Nullen)/\1^(\2^\3)\4/'"'"' \ - -e '"'"'s/(10)([1-9][0-9]*)(.*(1|Eins) mit \2 Nullen)/\1\^\2\3/'"'"' \ - -e '"'"'s/(die Zahl 10)(60)/\1^\2/'"'"' \ - ${_lang}.dict - dictzip ${_lang}.dict -} -' . basic.sh -- cgit v1.2.3