From: Paul Hänsch Date: Wed, 6 Feb 2019 21:52:42 +0000 (+0100) Subject: implemented card ordering X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=e090b8bd26739537e895d60b931f82b64d8db6c4;p=confetti implemented card ordering --- diff --git a/cards/list.sh b/cards/list.sh index 8b911fb..6775191 100755 --- a/cards/list.sh +++ b/cards/list.sh @@ -6,21 +6,17 @@ unescape() { [ $# = 0 ] && sed -E 's;\\(.);\1;g' || printf %s "$*" |sed -E 's;\\ upcase=' y;abcdefghijklmnopqrstuvwxyzäöüé;ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜÉ;; ' card_fullname(){ - local card="$1" n1 n2 n3 n4 n5 + local card="$1" N n1 n2 n3 n4 n5 - local N="$(pdi_value "$card" N)" - local FN="$(pdi_value "$card" FN)" - local NICKNAME="$(pdi_value "$card" NICKNAME)" - - if [ "$FN" ]; then - printf %s "$FN" - elif [ "$N" ]; then + if pdi_value "$card" FN; then + return + elif N="$(pdi_value "$card" N)"; then IFS=\; read n1 n2 n3 n4 n5 <<-EOF $(pdi_value "$card" N) EOF printf '%s %s %s %s %s' "$n4" "$n2" "$n3" "$n1" "$n5" - elif [ "$NICKNAME" ]; then - printf '"%s"' "$NICKNAME" + else + pdi_value "$card" NICKNAME fi } @@ -154,8 +150,32 @@ filter_cards(){ '"$upcase""$fex" } +order_cards() { + local cardfile card + echo ORDER $order >&2 + + while read cardfile; do + card="$(pdi_load "$cardfile")" + + case $order in + firstname) + printf '%s %s\n' "$(card_fullname "$card")" "$cardfile" + ;; + lastname) + printf '%s %s\n' "$(pdi_value "$card" N || card_fullname "$card")" "$cardfile" + ;; + bdate) + printf '%s %s\n' "$(pdi_value "$card" BDAY || printf 0000-00-00)" "$cardfile" + ;; + esac + done \ + | sort \ + | sed -E 's;^.*\t;;g' +} + list_cards(){ filter_cards \ + | order_cards \ | while read cardfile; do print_card "$cardfile" done diff --git a/pdiread.sh b/pdiread.sh index 112a827..cbbc4e5 100755 --- a/pdiread.sh +++ b/pdiread.sh @@ -91,6 +91,7 @@ pdi_count(){ pdi_attrib(){ local card=":$1" name="$2" cnt="${3:-1}" while [ $cnt -gt 0 ]; do + [ "${card#*${BR}${name};}" = "$card" ] && return 1 card="${card#*${BR}${name};}" cnt=$((cnt - 1)) done @@ -100,6 +101,7 @@ pdi_attrib(){ pdi_value(){ local card="${BR}$1" name="$2" cnt="${3:-1}" while [ $cnt -gt 0 ]; do + [ "${card#*${BR}${name};*:}" = "$card" ] && return 1 card="${card#*${BR}${name};*:}" cnt=$((cnt - 1)) done