From 0a607f5eefec38cc7ef625f1692bd1d12e969f90 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 16 Aug 2007 12:03:57 +0000 Subject: 23764: allow hidden continuations in calendar entries allow UIDs to help with updates --- Functions/Calendar/calendar | 7 +++++++ Functions/Calendar/calendar_add | 29 +++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) (limited to 'Functions/Calendar') diff --git a/Functions/Calendar/calendar b/Functions/Calendar/calendar index 328da853c..b5df2ca72 100644 --- a/Functions/Calendar/calendar +++ b/Functions/Calendar/calendar @@ -293,6 +293,13 @@ fi showline=${line%%$'\n'*} else showline=$line + match=() + # Strip continuation lines starting " #". + while [[ $showline = (#b)(*$'\n')[[:space:]]##\#[^$'\n']##(|$'\n'(*)) ]]; do + showline="$match[1]$match[3]" + done + # Strip trailing empty lines + showline=${showline%%[[:space:]]#} fi if (( showall || (t >= start && (remaining || t <= stop || icount < showcount)) )) then diff --git a/Functions/Calendar/calendar_add b/Functions/Calendar/calendar_add index 8e6eca8b6..dc9f50c2b 100644 --- a/Functions/Calendar/calendar_add +++ b/Functions/Calendar/calendar_add @@ -12,7 +12,7 @@ setopt extendedglob local calendar newfile REPLY lastline opt local -a calendar_entries lockfiles -integer newdate done rstat nolock nobackup +integer my_date done rstat nolock nobackup autoload -U calendar_{read,lockfiles,scandate} @@ -42,10 +42,20 @@ if ! calendar_scandate -a "$*"; then print "$0: failed to parse date/time" >&2 return 1 fi -(( newdate = $REPLY )) +(( my_date = $REPLY )) # $calendar doesn't necessarily exist yet. +local -a match mbegin mend +local my_uid their_uid + +# Match a UID, a unique identifier for the entry inherited from +# text/calendar format. +local uidpat='(|*[[:space:]])UID[[:space:]]##(#b)([[:xdigit:]]##)(|[[:space:]]*)' +if [[ "$*" = ${~uidpat} ]]; then + my_uid=$match[1] +fi + # start of block for following always to clear up lockfiles. { (( nolock )) || calendar_lockfiles $calendar || return 1 @@ -55,15 +65,22 @@ fi { for line in $calendar_entries; do - if (( ! done )) && calendar_scandate -a $line && (( REPLY > newdate )); then + if (( ! done )) && calendar_scandate -a $line && (( REPLY > my_date )); then print -r -- "$*" (( done = 1 )) - elif [[ $REPLY -eq $newdate && $line = "$*" ]]; then + fi + # Don't save this entry if it has the same UID as the new one. + if [[ -n $my_uid && $line = ${~uidpat} ]]; then + their_uid=$match[1] + [[ ${(U)my_uid} = ${(U)their_uid} ]] && continue + fi + if [[ $REPLY -eq $my_date && $line = "$*" ]]; then + (( done )) && continue # paranoia: shouldn't happen (( done = 1 )) fi print -r -- $line - done - (( done )) || print -r -- "$*" + done + (( done )) || print -r -- "$*" } >$newfile if (( ! nobackup )); then if ! mv $calendar $calendar.old; then -- cgit 1.4.1