]> git.plutz.net Git - confetti/commitdiff
updating function
authorPaul Hänsch <paul@plutz.net>
Thu, 4 Apr 2019 14:04:52 +0000 (16:04 +0200)
committerPaul Hänsch <paul@plutz.net>
Thu, 4 Apr 2019 14:04:52 +0000 (16:04 +0200)
pdiread.sh

index 89523d06ea43edc91c7b48aa18baf9b618b8363c..d2eb9fa2501b30cbf4eeed78fd93d87513d0505f 100755 (executable)
@@ -32,8 +32,8 @@ pdi_load() {
     :X $bY; N; bX; :Y s;^.*$;\n&\n;;
 
     # === Join continuing lines, strip trailing CRs ===
-    s;\r\n[ \t];;g;
-    s;\r\n;\n;g;
+    s;\r*\n[ \t];;g;
+    s;\r*\n;\n;g;
 
     # === turn property names to upper case, strip group names ===
     s;\n([^;:\.\n]+\.)([^;:\n]+);\n\2;g;
@@ -120,10 +120,29 @@ pdi_attrib(){
 
 pdi_value(){
   local card="${BR}$1" name="$2" cnt="${3:-1}"
-  while [ $cnt -gt 0 ]; do
+  while [ "$cnt" -gt 0 ]; do
     [ "${card#*${BR}${name};*:}" = "$card" ] && return 1
     card="${card#*${BR}${name};*:}"
     cnt=$((cnt - 1))
   done
   printf %s\\n "${card%%${BR}*}"
 }
+
+pdi_update_value(){
+  local card="${BR}$1" name="$2" cnt="$3" val="$4"
+  while [ "$cnt" -gt 0 ]; do
+    if [ "${card#*${BR}${name};*:}" = "${card}" ]; then
+       printf '%s\n%s;:' "${card%${BR}END:VCARD*}" "${name}"
+       card="${BR}END;:VCARD"
+       break;
+    else
+       printf '%s\n%s;' "${card%%${BR}${name};*}" "${name}"
+       card="${card#*${BR}${name};}"
+       printf '%s:' "${card%%:*}"
+       card="${card#*:}"
+    fi
+    cnt=$((cnt - 1))
+  done
+  printf '%s\n' "$val"
+  printf '%s\n' "${card#*${BR}}"
+}