refactoring card display
[confetti] / cards / cards.sh
index a90981c..a26b1fc 100755 (executable)
@@ -103,142 +103,6 @@ listcards() {
   | sed -r 's;^(.*/)*;;;'
 }
 
-vcf_parse() {
-  unset key
-  sed -r ':X;N;$!bX; s;\r\n[ \t];;g; s;\r\n;\n;g;' "$1" \
-  | sed -rn '
-    # === turn property names to upper case, strip group names ===
-    h; s;^([^;:]+);;;
-    x; s;^([^;:\.]+\.)?([^;:]+).*$;\2;;
-    y;abcdefghijklmnopqrstuvwxyz;ABCDEFGHIJKLMNOPQRSTUVWXYZ;
-    G; s;\n;;;
-
-    # === strip trailing CR (but keep CRs in property value) ===
-    s;\r$;;;
-
-    # === Normalise various known vendor properties ===
-                s;^X-MS-CARDPICTURE(\;|:);PHOTO\1;;
-                        s;^X-GENDER(\;|:);GENDER\1;;
-                   s;^X-ANNIVERSARY(\;|:);ANNIVERSARY\1;;
-         s;^X-EVOLUTION-ANNIVERSARY(\;|:);ANNIVERSARY\1;;
-    s;^X-KADDRESSBOOK-X-ANNIVERSARY(\;|:);ANNIVERSARY\1;;
-            s;^X-EVOLUTION-BLOG-URL(\;|:);URL\1;;
-                              s;^AGENT(\;|:);RELATED\;VALUE=text\;TYPE=agent\1;;
-                        s;^X-ASSISTANT(\;|:);RELATED\;VALUE=text\;TYPE=assistant\1;;
-              s;^X-EVOLUTION-ASSISTANT(\;|:);RELATED\;VALUE=text\;TYPE=assistant\1;;
-    s;^X-KADDRESSBOOK-X-ASSISTANTSNAME(\;|:);RELATED\;VALUE=text\;TYPE=assistant\1;;
-                          s;^X-MANAGER(\;|:);RELATED\;VALUE=text\;TYPE=manager\1;;
-                s;^X-EVOLUTION-MANAGER(\;|:);RELATED\;VALUE=text\;TYPE=manager\1;;
-      s;^X-KADDRESSBOOK-X-MANAGERSNAME(\;|:);RELATED\;VALUE=text\;TYPE=manager\1;;
-                           s;^X-SPOUSE(\;|:);RELATED\;VALUE=text\;TYPE=spouse\1;;
-                 s;^X-EVOLUTION-SPOUSE(\;|:);RELATED\;VALUE=text\;TYPE=spouse\1;;
-        s;^X-KADDRESSBOOK-X-SPOUSENAME(\;|:);RELATED\;VALUE=text\;TYPE=spouse\1;;
-
-    # === Normalise obsolete vendor IM properties ===
-            s;^X-AIM((\;[A-z0-9-]+|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:aim:;;
-            s;^X-ICQ((\;[A-z0-9-]+|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:aim:;;
-    s;^X-GOOGLE-TALK((\;[A-z0-9-]+|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:xmpp:;;
-         s;^X-JABBER((\;[A-z0-9-]+|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:xmpp:;;
-            s;^X-MSN((\;[A-z0-9-]+|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:msn:;;
-          s;^X-YAHOO((\;[A-z0-9-]+|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):;IMPP\1:ymsgr:;;
-            s;^X-SIP((\;[A-z0-9-]+|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(sip:)?;IMPP\1:sip:;;
-
-    # === Update obsolete LABEL property ===
-    s;^LABEL((\;[A-z0-9-]+|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$;ADR\1\;LABEL="\5":;;
-
-    /^([A-Z0-9-]+)((\;[A-z0-9-]+=?|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$/{
-      h;
-      s;^([A-Z0-9-]+)((\;[A-z0-9-]+=?|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$;key='\''\1'\'';;
-      H; g;
-
-      s;^([A-Z0-9-]+)((\;[A-z0-9-]+=?|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):([^\n]*)\n.*$;\2;;
-      s;'\'';'\'\\\\\'\'';g
-      s;\;([A-Z0-9-]+)(=|=(([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*))?;\ntag[\1]='\''\3'\'';g
-      s;^\n+;;; s;\n+$;;;
-      /^.+$/H; g;
-
-      s;^([A-Z0-9-]+)((\;[A-z0-9-]+=?|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):([^\n]*)\n.*$;\6;;
-      # :X s;((^|[^\\])(\\\\)*)[;,];\1\n;g; s;((^|[^\\])(\\\\)*)\\([;,]);\4;g; tX;
-      s;'\'';'\'\\\\\'\'';g
-      s;^.*$;value='\''&'\'';
-      H; g;
-
-      s;^[^\n]*[\n ]+;;
-      s;\n+$;;;
-
-      p;
-    }
-    ' \
-  | while read -r line; do
-    declare -A tag
-    case "$line" in
-      value*) eval "$line";;
-      tag*)   eval "$line";;
-      key*)
-        if [ -z "$key" ]; then
-          eval "$line"
-        else
-          printf '%s\n' "$value" |sed -rn '
-            :X
-            s;((^|[^\\])(\\\\)*),;\1\n;g; 
-            tX;
-            s;\\,;,;g;
-            p
-          ' \
-          | while read -r val; do
-            while [ -n "${values[$key$n]+x}" ]; do n=$((${n=-1} + 1)); done
-            if printf '%s\n' "$val" |grep -qE '((^|[^\\])(\\\\)*)\;'; then
-              m=0
-              values[${key}${n}]="${val}"
-              printf '%s\n' "$val" |sed -rn '
-                :X
-                s;((^|[^\\])(\\\\)*)\;;\1\n;g; 
-                tX;
-                s;\\\;;\;;g;
-                p
-              ' \
-              | while read -r v; do
-                values[${key}${n}+${m}]="$(
-                  printf %s\\n "${v}" \
-                  | sed -rn '
-                    :X
-                    s;((^|[^\\])(\\\\)*)\\n;\1\n;g; 
-                    tX;
-                    s;\\\\;\\;g;
-                    p
-                  '
-                )"
-                m=$(($m + 1))
-              done
-            else
-              values[${key}${n}]="$(
-                printf %s\\n "${val}" \
-                | sed -rn '
-                  :X
-                  s;((^|[^\\])(\\\\)*)\\n;\1\n;g; 
-                  tX;
-                  s;\\\;;\;;g;
-                  s;\\\\;\\;g;
-                  p
-                '
-              )"
-            fi
-            for t in ${(k)tag}; do
-              values[${key}${n}_${t}]="${tag[$t]}"
-            done
-          done
-
-          eval "$line"
-          unset n
-          while [ -n "${values[$key$n]+x}" ]; do n=$((${n=-1} + 1)); done
-          unset value
-          unset tag
-        fi
-      ;;
-    esac
-  done
-}
-
 view_card() {  #Parameter: Cardfile
   id="$1"
   cardfile="$_DATA/vcard/${id}"