From 751d678a319fdf0730023e06e375565f8039aee3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Sun, 4 Aug 2019 19:44:01 +0200 Subject: [PATCH 1/1] bugfix in un-aggregation of fields, attribute selection in pdi_attrib() --- pdiread.sh | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/pdiread.sh b/pdiread.sh index d774ada..8118318 100755 --- a/pdiread.sh +++ b/pdiread.sh @@ -56,7 +56,7 @@ pdi_load() { # === Unscramble aggregated fields === :disag - s;\n([^:]+:)((.*[^\])?(\\\\)*),;\n\1\2\n\1;; + s;\n([^:\n]+:)(([^\n]*[^\])?(\\\\)*),;\n\1\2\n\1;; t disag; # === Insert FN when only N is present === @@ -114,13 +114,31 @@ pdi_count(){ } pdi_attrib(){ - local card=":$1" name="$2" cnt="${3:-1}" + local card=":$1" name="$2" cnt="${3:-1}" attr="$4" while [ $cnt -gt 0 ]; do [ "${card#*${BR}${name};}" = "$card" ] && return 1 card="${card#*${BR}${name};}" cnt=$((cnt - 1)) done - printf %s\\n "${card%%:*}" + card="${card%%:*}" + if [ "$attr" ]; then + case $card in + *\;"$attr"=*) card="${card#*;${attr}=}";; + "$attr"=*) card="${card#${attr}=}";; + "$attr"|*\;"$attr"|"$attr"\;*|*\;"$attr"\;*) return 0;; + *) return 1;; + esac + case $card in + \"*\"\;*|\'*\'\;*) + card="${card#[\"\']}"; card="${card%%[\"\'];*}" + ;; + \"*\"|\'*\') + card="${card#[\"\']}"; card="${card%%[\"\']}" + ;; + *\;*) card="${card%%;*}";; + esac + fi + printf %s\\n "${card}" } pdi_value(){ -- 2.39.2