]> git.plutz.net Git - lobster/commitdiff
unify vcf parsers
authorpaul <paul@plutz.net>
Thu, 10 Nov 2016 14:05:21 +0000 (14:05 +0000)
committerpaul <paul@plutz.net>
Thu, 10 Nov 2016 14:05:21 +0000 (14:05 +0000)
svn path=/trunk/; revision=140

actions/generate_courselist.sh
pages/cards.sh
templates/edit_attendee.sh
templates/edit_client.sh
templates/view_attendee.sh
templates/view_client.sh

index f2f2aecddaf5506844dcee0e56a656f8e6354c40..35c9fac6041c9afb5c263855c3729d634e28dddc 100755 (executable)
@@ -35,36 +35,10 @@ list_attendee() {  #Parameter: Cardfile
   id="$1"
   cardfile="$_DATA/vcard/${id}"
 
-  unset key
-  declare -A tags
   declare -A values
 
   if [ -r "$cardfile" ]; then
-    vcf_parse "$cardfile" |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
-            values[$key]="$(tex_clean "$value")"
-            for t in ${(k)tag}; do
-              tags[${key}_$t]="$tag[$t]"
-            done
-            eval "$line"
-            if [ -n "$values[$key]" ]; then
-              n=0
-              while [ -n "$values[$key$n]" ]; do n=$(($n + 1)); done
-              key=$key$n
-            fi
-            unset value
-            unset tag
-          fi
-        ;;
-      esac
-    done
+    vcf_parse "$cardfile"
 
     n=$(printf %s "$values[N]" \
         | sed -rn 's:^([^;]*)(;[^;]*)(;[^;]*)?(;[^;]*)?(;[^;]*)?$:\4 \2 \3 \1 \5:gp' \
index 0ead803fb32304a581ba5fcdaae35bcd2e8413de..3f0be4a8167ac0d2db5cafb57f09aea19ba60f9e 100755 (executable)
@@ -102,14 +102,17 @@ listcards() {
 }
 
 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 ===
-    h; s;^([^\;:]+);;;
-    x; s;^([^\;:]+).*$;\1;;
+    # === turn property names to upper case, strip group names ===
+    h; s;^([^;:]+);;;
+    x; s;^([^;:\.]+\.)?([^;:]+).*$;\2;;
     y;abcdefghijklmnopqrstuvwxyz;ABCDEFGHIJKLMNOPQRSTUVWXYZ;
     G; s;\n;;;
 
+    
+
     # === Normalise various known vendor properties ===
                 s;^X-MS-CARDPICTURE(\;|:);PHOTO\1;;
                         s;^X-GENDER(\;|:);GENDER\1;;
@@ -129,73 +132,76 @@ vcf_parse() {
         s;^X-KADDRESSBOOK-X-SPOUSENAME(\;|:);RELATED\;VALUE=text\;TYPE=spouse\1;;
 
     # === Normalise obsolete vendor IM properties ===
-            s;^X-AIM((\;[a-zA-Z0-9-]+|\;[a-zA-Z0-9-]+=([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*)*):;IMPP\1:aim:;;
-            s;^X-ICQ((\;[a-zA-Z0-9-]+|\;[a-zA-Z0-9-]+=([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*)*):;IMPP\1:aim:;;
-    s;^X-GOOGLE-TALK((\;[a-zA-Z0-9-]+|\;[a-zA-Z0-9-]+=([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*)*):;IMPP\1:xmpp:;;
-         s;^X-JABBER((\;[a-zA-Z0-9-]+|\;[a-zA-Z0-9-]+=([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*)*):;IMPP\1:xmpp:;;
-            s;^X-MSN((\;[a-zA-Z0-9-]+|\;[a-zA-Z0-9-]+=([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*)*):;IMPP\1:msn:;;
-          s;^X-YAHOO((\;[a-zA-Z0-9-]+|\;[a-zA-Z0-9-]+=([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*)*):;IMPP\1:ymsgr:;;
-            s;^X-SIP((\;[a-zA-Z0-9-]+|\;[a-zA-Z0-9-]+=([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*)*):(sip:)?;IMPP\1:sip:;;
+            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-zA-Z0-9-]+|\;[a-zA-Z0-9-]+=([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*)*):(.*)$;ADR\1\;LABEL="\5":;;
+    s;^LABEL((\;[a-Z0-9-]+|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$;ADR\1\;LABEL="\5":;;
 
-    /^([a-zA-Z0-9-]+)((\;[a-zA-Z0-9-]+=?|\;[a-zA-Z0-9-]+=([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*)*):(.*)$/{
+    /^([A-Z0-9-]+)((\;[a-Z0-9-]+=?|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$/{
       h;
-      s;^([a-zA-Z0-9-]+)((\;[a-zA-Z0-9-]+=?|\;[a-zA-Z0-9-]+=([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*)*):(.*)$;key='\''\1'\'';;
+      s;^([A-Z0-9-]+)((\;[a-Z0-9-]+=?|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$;key='\''\1'\'';;
       H; g;
-      s;^([a-zA-Z0-9-]+)((\;[a-zA-Z0-9-]+=?|\;[a-zA-Z0-9-]+=([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*)*):([^\n]*)\n.*$;\6;;
+
+      s;^([A-Z0-9-]+)((\;[a-Z0-9-]+=?|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):([^\n]*)\n.*$;\2;;
       s;'\'';'\'\\\\\'\'';g
-      s;^.*$;value='\''&'\'';
-      H; g;
-      s;^([a-zA-Z0-9-]+)((\;[a-zA-Z0-9-]+=?|\;[a-zA-Z0-9-]+=([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*)*):([^\n]*)\n.*$;\2;;
+      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;\;([a-zA-Z0-9-]+)(=|=(([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*))?;\ntag[\1]='\''\3'\'';g
+      s;^.*$;value='\''&'\'';
       H; g;
-      s;^[^\n]*[\n ]+;;
 
-      s;\n[\n ]+;\n;g; s;\n$;;;
+      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
+          values[${key}]="${value//\\r\\n/$BR}"
+          for t in ${(k)tag}; do
+            values[${key}_${t}]="${tag[$t]}"
+          done
+          eval "$line"
+          if [ -n "$values[$key]" ]; then
+            n=0
+            while [ -n "$values[$key$n]" ]; do n=$(($n + 1)); done
+            key=$key$n
+          fi
+          unset value
+          unset tag
+        fi
+      ;;
+    esac
+  done
 }
 
 view_card() {  #Parameter: Cardfile
   id="$1"
   cardfile="$_DATA/vcard/${id}"
   cachefile="$_DATA/cache/${id}.cache"
-  unset key
   if [ "$cachefile" -nt "$cardfile" ]; then
     cat "$cachefile"
   else
-    declare -A tags
     declare -A values
-    vcf_parse "$cardfile" |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
-            values[$key]="${value//\\r\\n/$BR}"
-            for t in ${(k)tag}; do
-              tags[${key}_$t]="$tag[$t]"
-            done
-            eval "$line"
-            if [ -n "$values[$key]" ]; then
-              n=0
-              while [ -n "$values[$key$n]" ]; do n=$(($n + 1)); done
-              key=$key$n
-            fi
-            unset value
-            unset tag
-          fi
-        ;;
-      esac
-    done
+    vcf_parse "$cardfile"
     . $view_card |tee "$cachefile"
   fi
 }
@@ -205,34 +211,8 @@ edit_card() {  #Parameter: Cardfile
   cardfile="$_DATA/vcard/$id"
   tempfile="$_DATA/temp/$id"
   [ -f "$tempfile" ] && cardfile="$tempfile"
-  unset key
 
-  declare -A tags
   declare -A values
-  vcf_parse "$cardfile" |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
-          [ -n "$value" ] && values[$key]="${value//\\r\\n/$BR}" || values[$key]='\r'
-          for t in ${(k)tag}; do
-            tags[${key}_$t]="$tag[$t]"
-          done
-          eval "$line"
-          if [ -n "$values[$key]" ]; then
-            n=0
-            while [ -n "$values[${key}${n}]" ]; do n=$(($n + 1)); done
-            key=$key$n
-          fi
-            unset value
-            unset tag
-        fi
-      ;;
-    esac
-  done
+  vcf_parse "$cardfile"
   . $edit_card
 }
index f12633da01b3dfa2dcc4827a8e5f88f9711fdee8..047879ad84f5d994f247c1d5431a8cf60b2ac8f8 100755 (executable)
@@ -70,8 +70,8 @@ cat <<END_HTML
       echo '      <source type="audio/ogg" src="data:audio/ogg;base64,'$values[SOUND]'" />'
       echo '    </audio>'
     fi)
-    ${values[PHOTO]:+<img class="item PHOTO" src="data:image/$tags[PHOTO_TYPE];base64,$values[PHOTO]" />}
-    ${values[LOGO]:+<img class="item LOGO" src="data:image/$tags[LOGO_TYPE];base64,$values[LOGO]" />}
+    ${values[PHOTO]:+<img class="item PHOTO" src="data:image/$values[PHOTO_TYPE];base64,$values[PHOTO]" />}
+    ${values[LOGO]:+<img class="item LOGO" src="data:image/$values[LOGO_TYPE];base64,$values[LOGO]" />}
   </div>
 
   <div class="section phone">
index ed51dde51fdec9ef839c9f41983b2097fba5e707..b2331aa8e9e83084eb745df411e2af8727a91cdc 100755 (executable)
@@ -85,8 +85,8 @@ cat <<END_HTML
       echo '      <source type="audio/ogg" src="data:audio/ogg;base64,'$values[SOUND]'" />'
       echo '    </audio>'
     fi)
-    ${values[PHOTO]:+<img class="item PHOTO" src="data:image/$tags[PHOTO_TYPE];base64,$values[PHOTO]" />}
-    ${values[LOGO]:+<img class="item LOGO" src="data:image/$tags[LOGO_TYPE];base64,$values[LOGO]" />}
+    ${values[PHOTO]:+<img class="item PHOTO" src="data:image/$values[PHOTO_TYPE];base64,$values[PHOTO]" />}
+    ${values[LOGO]:+<img class="item LOGO" src="data:image/$values[LOGO_TYPE];base64,$values[LOGO]" />}
   </div>
 
   <div class="section address">
@@ -103,9 +103,9 @@ cat <<END_HTML
 
   <div class="section phone">
     <h3>$(l10n TEL)</h3>
-    $(teltype "${tags[TEL_TYPE]}")<input class="item TEL" name="TEL" value="$values[TEL]" />
+    $(teltype "${values[TEL_TYPE]}")<input class="item TEL" name="TEL" value="$values[TEL]" />
     $(for n in TEL{0..10}; do
-      printf "${values[$n]:+$(teltype "${tags[$n_TYPE]}")<input class="item TEL" name="TEL" value="'$values[$n]'" />}"
+      printf "${values[$n]:+$(teltype "${values[${n}_TYPE]}")<input class="item TEL" name="TEL" value="'$values[$n]'" />}"
     done)
 
     <h3>$(l10n EMAIL)</h3>
index bdfdc6a621ebe2fe5ebfb0335f072d353d5c3352..1394cedacae447feae5e644e5b97c493a53da9af 100755 (executable)
@@ -34,14 +34,14 @@ cat <<END_HTML
     ${values[X-ZACK-JOINDATE]:+<span class="item X-ZACK-JOINDATE"><b>$(l10n label_join):</b> $values[X-ZACK-JOINDATE]</span>}
     ${values[X-ZACK-LEAVEDATE]:+<span class="item X-ZACK-LEAVEDATE"><b>$(l10n label_leave):</b> $values[X-ZACK-LEAVEDATE]</span>}
     ${values[SOUND]:+<audio controls="controls" class="item SOUND"><source type="audio/ogg" src="data:audio/ogg;base64,$values[SOUND]" /></audio>}
-    ${values[PHOTO]:+<img class="item PHOTO" src="data:image/$tags[PHOTO_TYPE];base64,$values[PHOTO]" />}
-    ${values[LOGO]:+<img class="item LOGO" src="data:image/$tags[LOGO_TYPE];base64,$values[LOGO]" />}
+    ${values[PHOTO]:+<img class="item PHOTO" src="data:image/$values[PHOTO_TYPE];base64,$values[PHOTO]" />}
+    ${values[LOGO]:+<img class="item LOGO" src="data:image/$values[LOGO_TYPE];base64,$values[LOGO]" />}
   </div><!--
 
   --><div class="section phone">
     <h3>$(l10n TEL)</h3>
     $(for n in TEL TEL{0..10}; do
-      echo "${values[$n]:+<span class="item TEL">$tags[${n}_TYPE] $values[$n]</span>}"
+      echo "${values[$n]:+<span class="item TEL">$values[${n}_TYPE] $values[$n]</span>}"
     done)
   </div><!--
 
@@ -52,7 +52,7 @@ cat <<END_HTML
     done)
     ${values[IMPP]:+<h3>$(l10n IMPP)</h3>}
     $(for n in IMPP IMPP{0..10}; do
-      echo "${values[$n]:+<span class="item IMPP">$tags[${n}_TYPE] <a href="$values[$n]">$values[$n]</a></span>}"
+      echo "${values[$n]:+<span class="item IMPP">$values[${n}_TYPE] <a href="$values[$n]">$values[$n]</a></span>}"
     done)
   </div><!--
 
index c83fac9fd18f966cc396eae2422e8a1500a99237..2cb124bb71a88fa6f4f76a1a757b2115beff31ae 100755 (executable)
@@ -37,8 +37,8 @@ cat <<END_HTML
 
     ${values[BDAY]:+<span class="\""item BDAY"\""><label>*:</label> ${values[BDAY]}</span>}
     ${values[SOUND]:+<audio controls="controls" class="\""item SOUND"\""><source type="audio/ogg" src="\""data:audio/ogg;base64,$values[SOUND]"\"" /></audio>}
-    ${values[PHOTO]:+<img class="\""item PHOTO"\"" src="\""data:image/$tags[PHOTO_TYPE];base64,$values[PHOTO]"\"" />}
-    ${values[LOGO]:+<img class="\""item LOGO"\"" src="\""data:image/$tags[LOGO_TYPE];base64,$values[LOGO]"\"" />}
+    ${values[PHOTO]:+<img class="\""item PHOTO"\"" src="\""data:image/$values[PHOTO_TYPE];base64,$values[PHOTO]"\"" />}
+    ${values[LOGO]:+<img class="\""item LOGO"\"" src="\""data:image/$values[LOGO_TYPE];base64,$values[LOGO]"\"" />}
 
     <h3>$(l10n ADR)</h3>
     $(for n in ADR ADR{0..10}; do
@@ -53,7 +53,7 @@ cat <<END_HTML
   --><div class="section phone">
     <h3>$(l10n TEL)</h3>
     $(for n in TEL TEL{0..10}; do
-      echo "${values[$n]:+<span class="\""item TEL"\"">$(l10n t${tags[${n}_TYPE]}) $values[$n]</span>}"
+      echo "${values[$n]:+<span class="\""item TEL"\"">$(l10n t${values[${n}_TYPE]}) $values[$n]</span>}"
     done)
     ${values[EMAIL]:+<h3>$(l10n EMAIL)</h3>}
     $(for n in EMAIL EMAIL{0..10}; do
@@ -61,7 +61,7 @@ cat <<END_HTML
     done)
     ${values[IMPP]:+<h3>$(l10n IMPP)</h3>}
     $(for n in IMPP IMPP{0..10}; do
-      echo "${values[$n]:+<span class="\""item IMPP"\"">$tags[${n}_TYPE] <a href="\""$values[$n]"\"">$values[$n]</a></span>}"
+      echo "${values[$n]:+<span class="\""item IMPP"\"">$values[${n}_TYPE] <a href="\""$values[$n]"\"">$values[$n]</a></span>}"
     done)
   </div><!--