From: Paul Hänsch Date: Thu, 4 Apr 2019 14:04:52 +0000 (+0200) Subject: updating function X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=db7a64bb18b94e041398560bb2dae6eb8f13855e;p=confetti updating function --- diff --git a/pdiread.sh b/pdiread.sh index 89523d0..d2eb9fa 100755 --- a/pdiread.sh +++ b/pdiread.sh @@ -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}}" +}