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
#!/bin/zsh
-# Copyright 2014 Paul Hänsch
+# Copyright 2014, 2016 Paul Hänsch
#
# This file is part of Confetti.
#
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
}