X-Git-Url: http://git.plutz.net/?p=confetti;a=blobdiff_plain;f=pdiread.sh;fp=pdiread.sh;h=e19ceb8d5150c658381ac3d017f54f0f0caa6721;hp=08fbaec3fb373c2fbb6cdde7974caaa520b849e3;hb=e4399b525cba748e3a1190639544634e42a24244;hpb=b7a7bb5c1a4acad9b0fae1df2f062f661fea71cd diff --git a/pdiread.sh b/pdiread.sh index 08fbaec..e19ceb8 100755 --- a/pdiread.sh +++ b/pdiread.sh @@ -1,6 +1,6 @@ #!/bin/zsh -# Copyright 2014 - 2018 Paul Hänsch +# Copyright 2014 - 2018, 2023 Paul Hänsch # # This file is part of Confetti. # @@ -25,16 +25,17 @@ include_pdi="$0" BR=' ' - -unescape() { - local unescape='s;(^(\\\\)*|[^\\](\\\\)*)\\n;\1\n;g; s;\\(.);\1;g' - if [ $# -eq 0 ]; then - sed -E "$unescape" - else - printf %s "$*" \ - | sed -E "$unescape" - fi -} +unescape(){ + local in out='' + [ $# -gt 0 ] && in="$*" || in="$(cat)" + while [ "$in" ]; do case $in in + \\\\*) out="${out}\\"; in="${in#\\\\}" ;; + \\n*) out="${out}${BR}"; in="${in#\\n}" ;; + \\*) in="${in#\\}" ;; + *) out="${out}${in%%[\\]*}"; in="${in#"${in%%[\\]*}"}" ;; + esac; done + printf '%s\n' "$out" + } pdi_load() { # normalise PDI file for processing with pdi_* functions