#!/bin/sh
############################################################################
#
# Command-line interface for adding ical items.
#
# Usage:
#	icaladdlines [-calendar <calendar>]
#
#	Zero or more items are created and added to <calendar>.
#	The item descriptions are read from standard input, one per line.
#
#	The date and times are extracted from the standard input if
#	possible.  If a date cannot be extracted, it defaults to
#	today.
#
#	If time information cannot be extracted, the item is made a
#	notice instead of an appointment.  If a time range can be
#	extracted, then the item is made an appointment that spans
#	that time range.  If only a single time occurrence can be
#	extracted, then the item is made an appointment that starts at
#	that time and lasts for an hour.
#
############################################################################
# Adapted from "icaladd" by "ark@research.att.com".

set kludge { ${1+"$@"}
shift
shift
exec ical -f $0 -nodisplay ${1+"$@"}
}

calendar cal $ical(calendar)

puts stderr =====
while {[gets stdin line] >= 0} {
    set item [item_parse $line]
    puts stderr [date2text [$item first]]
    puts -nonewline stderr [item2text $item]
    cal add [item_parse $line]
puts stderr =====
}

cal save
