]> git.plutz.net Git - confetti/blobdiff - pdiread.sh
auto complete in attendant fields
[confetti] / pdiread.sh
index 8118318d3d4bdd4e2793d468c037b28b5006588f..e19ceb8d5150c658381ac3d017f54f0f0caa6721 100755 (executable)
@@ -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(){