]> git.plutz.net Git - confetti/commitdiff
bugfix in un-aggregation of fields, attribute selection in pdi_attrib()
authorPaul Hänsch <paul@plutz.net>
Sun, 4 Aug 2019 17:44:01 +0000 (19:44 +0200)
committerPaul Hänsch <paul@plutz.net>
Sun, 4 Aug 2019 17:44:01 +0000 (19:44 +0200)
pdiread.sh

index d774ada3caedba752d1271aa1bc8ceacc662b5d5..8118318d3d4bdd4e2793d468c037b28b5006588f 100755 (executable)
@@ -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(){