about summary refs log tree commit diff
path: root/Functions/Calendar/calendar_read
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2006-12-01 10:23:06 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2006-12-01 10:23:06 +0000
commit6b1b34d1da6b0db599c026e17df011ad6c6b3a30 (patch)
tree3559a344ebd62a8b0af17c70b9b0fdaeae5e2299 /Functions/Calendar/calendar_read
parentab8b8026dcc17f7c3d8dcfba7dba046b1ac7c42b (diff)
downloadzsh-6b1b34d1da6b0db599c026e17df011ad6c6b3a30.tar.gz
zsh-6b1b34d1da6b0db599c026e17df011ad6c6b3a30.tar.xz
zsh-6b1b34d1da6b0db599c026e17df011ad6c6b3a30.zip
c.f. 23023: new calendar function system.
Diffstat (limited to 'Functions/Calendar/calendar_read')
-rw-r--r--Functions/Calendar/calendar_read35
1 files changed, 35 insertions, 0 deletions
diff --git a/Functions/Calendar/calendar_read b/Functions/Calendar/calendar_read
new file mode 100644
index 000000000..ed163887f
--- /dev/null
+++ b/Functions/Calendar/calendar_read
@@ -0,0 +1,35 @@
+# Utility for "calendar" to read entries into the array calendar_entries.
+# This should be local to the caller.
+# The only argument is the file to read.  We expect options etc. to
+# be correct.
+#
+# This is based on Emacs calendar syntax, which has two implications:
+#  - Lines beginning with whitespace are continuation lines.
+#    Hence we have to read the entire file first to determine entries.
+#  - Lines beginning with "&" are inhibited from producing marks in
+#    Emacs calendar window.  This is irrelevant to us, so we
+#    we simply remove leading ampersands.  This is necessary since
+#    we expect the date to start at the beginning of the line.
+#
+# TODO: Emacs has some special handling for entries where the first line
+# has only the date and continuation lines indicate times.  Actually,
+# it doesn't parse the times as far as I can see, but if we want to
+# handle that format sensibly we would need to here.  It could
+# be tricky to get right.
+
+local calendar=$1 line
+local -a lines
+
+lines=(${(f)"$(<$calendar)"})
+
+calendar_entries=()
+# ignore blank lines
+for line in $lines; do
+  if [[ $line = [[:space:]]* ]]; then
+    if (( ${#calendar_entries} )); then
+      calendar_entries[-1]+=$'\n'$line
+    fi
+  else
+    calendar_entries+=(${line##\&})
+  fi
+done