X-Git-Url: https://git.plutz.net/?p=confetti;a=blobdiff_plain;f=pdiread.sh;h=08fbaec3fb373c2fbb6cdde7974caaa520b849e3;hp=8118318d3d4bdd4e2793d468c037b28b5006588f;hb=HEAD;hpb=5ab459e666f2526f671fe222cd1646a4e6798b27 diff --git a/pdiread.sh b/pdiread.sh index 8118318..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,6 +25,17 @@ include_pdi="$0" BR=' ' +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 @@ -32,7 +43,7 @@ pdi_load() { # Usage example: # data="$(pdi_load file.vcf)" - sed -En ' + sed -srn ' # === Read entire file into buffer === :X $bY; N; bX; :Y s;^.*$;\n&\n;; @@ -100,7 +111,7 @@ pdi_load() { # === Update obsolete LABEL property === s;\nLABEL((\;[A-Za-z0-9-]+|\;[A-Za-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)\n;\nADR\1\;LABEL="\5":\n;g; - p;' "$1" + p;' "$@" } pdi_count(){