From: Paul Hänsch Date: Sun, 14 Feb 2021 10:18:33 +0000 (+0100) Subject: updated escape vcf functions X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=0f24ecb921cf09e1760a3a4f08197b5c260d7c16;p=lobster updated escape vcf functions --- diff --git a/cards/export_csv.sh b/cards/export_csv.sh index 9ba8993..dd1d6e7 100755 --- a/cards/export_csv.sh +++ b/cards/export_csv.sh @@ -13,7 +13,7 @@ order="$(GET o)" list_attendance() { grep -F " ${cardfile##*/}" "$_DATA/mappings/attendance" |while read each discard; do - { pdi_value "$(pdi_load "$_DATA/ical/$each")" SUMMARY || l10n "(unnamed course)"; } |unescape + { pdi_value "$(pdi_load "$_DATA/ical/$each")" SUMMARY || l10n "(unnamed course)"; } |pdi_unescape done \ | sed -E 's;";\\";g;' } @@ -25,7 +25,7 @@ list_item() { seq 1 $cnt |while read n; do case $item in TEL) - tel="$(pdi_value "$card" "$item" "$n" |unescape)" + tel="$(pdi_value "$card" "$item" "$n" |pdi_unescape)" ttype="$(pdi_attrib "$card" "$item" "$n" TYPE)" if [ "$tel" -a "$ttype" ]; then printf '%s: %s\n' "$(l10n "TYPE=$ttype")" "$tel" @@ -34,10 +34,10 @@ list_item() { fi ;; GENDER) - gen="$(pdi_value "$card" "$item" "$n" |unescape)" + gen="$(pdi_value "$card" "$item" "$n" |pdi_unescape)" [ "$gen" ] && l10n "gender_$gen" ;; - *) pdi_value "$card" "$item" "$n" |unescape + *) pdi_value "$card" "$item" "$n" |pdi_unescape ;; esac; done \ | sed -E 's;";\\";g;' diff --git a/cards/new_card.sh b/cards/new_card.sh index 0273a2c..a8afc7a 100755 --- a/cards/new_card.sh +++ b/cards/new_card.sh @@ -23,14 +23,6 @@ order="$(REF o)" uid="$(timeid)$(randomid)" # 32 Octets UID, starting with timestamp card="${uid}.vcf" -vcf_escape(){ - for each in "$@"; do - printf %s\\n "$each" \ - | sed -E ':X;$!{N;bX}; s;\r\n;\n;g; s;([;,\\]);\\\1;g; s;\n;\\n;g;' - done \ - | sed -E ':X;$!{N;bX}; s;\n;\;;g' -} - IFS='|' read -r date fn ln bmonth byear tel tcell junk1 email junk2 note <<-EOF $(POST seed |tr \\t \|) EOF @@ -55,15 +47,15 @@ if mkdir "$lockdir"; then cat >"$lockfile" <<-EOF BEGIN:VCARD VERSION:4.0 - N:$(vcf_escape "$ln" "$fn" "$mn" "" "") - FN:$(vcf_escape "${fn}${mn:+ }${mn} ${ln}") + N:$(pdi_escape "$ln" "$fn" "$mn" "" "") + FN:$(pdi_escape "${fn}${mn:+ }${mn} ${ln}") BDAY:$(parse_date "${byear}-${bmonth}-01") - TEL:$(vcf_escape "$tel") - TEL;TYPE=CELL:$(vcf_escape "$tcell") - EMAIL:$(vcf_escape "$email") + TEL:$(pdi_escape "$tel") + TEL;TYPE=CELL:$(pdi_escape "$tcell") + EMAIL:$(pdi_escape "$email") X-ZACK-JOINDATE:$(parse_date "$date") ADR: - NOTE:$(vcf_escape "$note") + NOTE:$(pdi_escape "$note") UID:${uid} END:VCARD EOF diff --git a/cards/update_card.sh b/cards/update_card.sh index 2ee6931..7bfca2f 100755 --- a/cards/update_card.sh +++ b/cards/update_card.sh @@ -59,8 +59,8 @@ n1="$(POST 1N)" n2="$(POST 2N)" n3="$(POST 3N)" n4="$(POST 4N)" n5="$(POST 5N)" # 3N (Middle Names) is not actually used n3="${n2#${n2%% *}}" -vcf="$(pdi_update_value "$vcf" N 1 "$(vcf_escape "$n1" "${n2%% *}" "${n3# }" "$n4" "$n5")")" -vcf="$(pdi_update_value "$vcf" FN 1 "$(vcf_escape "$n4 $n2 $n1 $n5" |sed -E 's;(^ +| +$);;g; s; +; ;g;')")" +vcf="$(pdi_update_value "$vcf" N 1 "$(pdi_escape "$n1" "${n2%% *}" "${n3# }" "$n4" "$n5")")" +vcf="$(pdi_update_value "$vcf" FN 1 "$(pdi_escape "$n4 $n2 $n1 $n5" |sed -E 's;(^ +| +$);;g; s; +; ;g;')")" vcf="$(printf '%s\n' "$vcf" |sed -E "/^CATEGORIES;[^:]*:.*$/d")" for field in $(POST_KEYS |grep -xE '[A-Z][A-Z0-9-]*'); do diff --git a/cards/widgets.sh b/cards/widgets.sh index 9a71f19..ab317fb 100755 --- a/cards/widgets.sh +++ b/cards/widgets.sh @@ -22,12 +22,12 @@ cat <[label for="hi_select_list" $(l10n hi_from_list)][input type="radio" name="$item" value="other" #hi_other checked][label for="hi_other" $(l10n hi_other)][select class="item" name="hi_company" + [radio "$item" "list" .tab #hi_select_list checked][label for="hi_select_list" $(l10n hi_from_list)] + [radio "$item" "other" .tab #hi_other][label for="hi_other" $(l10n hi_other)] + [select .tab .item name="hi_company" [option value="" disabled="disabled" $(selected "${hi_name}" "") . $(l10n hi_company)] $(list_hi_companies |while read f; do printf '[option value="%s" %s . %s]' "$(pdi_unescape "$f" |HTML)" \ @@ -268,9 +266,9 @@ edit_item(){ "$(pdi_unescape "$f" |HTML)" done) ] - [input type="text" name="hi_other" value="$hi_name" placeholder="$(l10n hi_company)"] - [input name="hi_number" value="$(pdi_unescape "$hi_number" |HTML)" placeholder="$(l10n hi_number)"] - [input name="hi_status" value="$(pdi_unescape "$hi_status" |HTML)" placeholder="$(l10n hi_status)"] + [input type="text" .tab name="hi_other" value="$hi_name" placeholder="$(l10n hi_company)"] + [input type="text" name="hi_number" value="$(pdi_unescape "$hi_number" |HTML)" placeholder="$(l10n hi_number)"] + [input type="text" name="hi_status" value="$(pdi_unescape "$hi_status" |HTML)" placeholder="$(l10n hi_status)"] EOF done ;; diff --git a/pdiread.sh b/pdiread.sh index f547cb6..58baa88 100755 --- a/pdiread.sh +++ b/pdiread.sh @@ -26,16 +26,6 @@ include_pdi="$0" BR=' ' -unescape() { - local unescape='s;(^(\\\\)*|[^\\](\\\\)*)\\n;\1\n;g; s;\\(.);\1;g' - if [ $# -eq 0 ]; then - sed -E "$unescape" - else - printf %s "$*" \ - | sed -E "$unescape" - fi -} - pdi_load() { # normalise PDI file for processing with pdi_* functions # functions in this library can only be applied to normalised data