From a8dcdb19d3c744ffb2b0776eea12546edaf06627 Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 7 Nov 2016 19:06:51 +0000 Subject: [PATCH] reduce faulty data display in course lists svn path=/trunk/; revision=138 --- actions/generate_courselist.sh | 88 ++++++++++++++++++---------------- pages/courses.sh | 29 +++++++---- 2 files changed, 66 insertions(+), 51 deletions(-) diff --git a/actions/generate_courselist.sh b/actions/generate_courselist.sh index 71eb80a..f2f2aec 100755 --- a/actions/generate_courselist.sh +++ b/actions/generate_courselist.sh @@ -34,52 +34,56 @@ tex_clean() { #in dire need for improvement list_attendee() { #Parameter: Cardfile id="$1" cardfile="$_DATA/vcard/${id}" - unset key + 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 - 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 - n=$(printf %s "$values[N]" \ - | sed -rn 's:^([^;]*)(;[^;]*)(;[^;]*)?(;[^;]*)?(;[^;]*)?$:\4 \2 \3 \1 \5:gp' \ - | sed -r 's:,: :;s:;: :g;s: +: :g;s:^ $::;' - ) - fullname="${n:-${values[FN]:-${values[NICKNAME]}}}" - - tel='' - for n in TEL TEL{0..10}; do if (echo "$values[$n]" |grep -Eq '[0-9]'); then - [ -n "$tel" ] && tel="$tel\\newline $values[$n]" || tel="$values[$n]" - fi; done - - note='' - for n in NOTE NOTE{0..10}; do if [ -n "$values[$n]" ]; then - [ -n "$note" ] && note="$note\\newline $values[$n]" || note="$values[$n]" - fi; done - echo -E "$fullname & $values[BDAY] & $tel & $note" + 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 + + n=$(printf %s "$values[N]" \ + | sed -rn 's:^([^;]*)(;[^;]*)(;[^;]*)?(;[^;]*)?(;[^;]*)?$:\4 \2 \3 \1 \5:gp' \ + | sed -r 's:,: :;s:;: :g;s: +: :g;s:^ $::;' + ) + fullname="${n:-${values[FN]:-${values[NICKNAME]}}}" + + tel='' + for n in TEL TEL{0..10}; do if (echo "$values[$n]" |grep -Eq '[0-9]'); then + [ -n "$tel" ] && tel="$tel\\newline $values[$n]" || tel="$values[$n]" + fi; done + + note='' + for n in NOTE NOTE{0..10}; do if [ -n "$values[$n]" ]; then + [ -n "$note" ] && note="$note\\newline $values[$n]" || note="$values[$n]" + fi; done + printf '%s & %s & %s & %s\n' "$fullname" "$values[BDAY]" "$tel" "$note" \ + | sed -r ':X;N;$!bX; s;\n;\\newline ;g' + fi } get_dates() { #Parameter: Calendarfile diff --git a/pages/courses.sh b/pages/courses.sh index ad92ae7..0fa5542 100755 --- a/pages/courses.sh +++ b/pages/courses.sh @@ -1,6 +1,6 @@ #!/bin/zsh -# Copyright 2014 Paul Hänsch +# Copyright 2014, 2016 Paul Hänsch # # This file is part of Confetti. # @@ -53,14 +53,25 @@ listcourses() { list_attendance() { id="$1" sed -rn 's:'$id'\t(.+)$:\1:p' "$_DATA/mappings/attendance" |while read each; do - n_last="$( sed -rn 's:^N(;.+)*\:([^;]*;){0} *([^;]*).*$:\3:p' "$_DATA/vcard/$each")" - n_first="$( sed -rn 's:^N(;.+)*\:([^;]*;){1} *([^;]*).*$:\3:p' "$_DATA/vcard/$each")" - n_middle="$(sed -rn 's:^N(;.+)*\:([^;]*;){2} *([^;]*).*$:\3:p' "$_DATA/vcard/$each")" - n_pre="$( sed -rn 's:^N(;.+)*\:([^;]*;){3} *([^;]*).*$:\3:p' "$_DATA/vcard/$each")" - n_post="$( sed -rn 's:^N(;.+)*\:([^;]*;){4} *([^;]*).*$:\3:p' "$_DATA/vcard/$each")" - byear="$( sed -rn 's:^BDAY(;.+)*\:([0-9]{4})(-[0-9][0-9]){2}.*$:\2:p' "$_DATA/vcard/$each")" - aname="${n_pre} ${n_first} ${n_middle} ${n_last} ${n_post} (*${byear})" - echo "$each $aname" |tr -d '\r' + card="$_DATA/vcard/$each" + if [ -r "$card" ]; then + aname="$(sed -rn ' + /^N(;.+)*:/{ + h; + s;^N(\;.+)*:([^\;]*\;){3} *([^\;]*).*$;\3;p; g; + s;^N(\;.+)*:([^\;]*\;){1} *([^\;]*).*$;\3;p; g; + s;^N(\;.+)*:([^\;]*\;){2} *([^\;]*).*$;\3;p; g; + s;^N(\;.+)*:([^\;]*\;){0} *([^\;]*).*$;\3;p; g; + s;^N(\;.+)*:([^\;]*\;){4} *([^\;]*).*$;\3;p; g; + }' "$card" \ + | sed -r ':X;N;$!bX; s;([\;\n\r,]| )+; ;g;; s;^ +| +$;;g;' + )" + fname="$(sed -rn 's;^FN(\;.+)*:(.+)\r?$;\2;g; s;([\;\n,]| )+; ;g;; s;^ +| +$;;g;' "$card")" + nname="$(sed -rn 's;^NICKNAME(\;.+)*:(.+)\r?$;\2;g; s;([\;\n,]| )+; ;g;; s;^ +| +$;;g;' "$card")" + byear="$(sed -rn 's:^BDAY(\;.+)*\:([0-9]{4})(-[0-9][0-9]){2}.*$:\2:p' "$_DATA/vcard/$each")" + + printf '%s %s (*%04i)\n' "$each" "${aname:-${fname:-${nname}}}" "$byear" + fi done } -- 2.39.2