
# First line blank so will be run by SH.
# This command has as standard output suitable contents for a LaTeX
# file which will print out a Registration Day sign up sheet.
# Messages monitoring execution progress are printed to standard error
# and are made into LaTeX comments in case they get merged with the output.

# The usage may be summarized as
#   reg date person interval start_time end_time ...
# Arguments containing spaces (e.g. the first 2) must be enclosed in quotes.
# The third argument is the number of minutes between appointments
# The times are in the format hour:minutes.
# There can be as many pairs of times as you want, appointments will be
# scheduled within each range.
# Here is an example of the usage of this command
#   reg 'Sept. 9' 'Charles Leiserson' 10 10:00 12:40 2:00 3:40 >reg.tex

if test $# -lt 5
then
  echo reg: '' usage: reg date person interval start_time end_time ... 1>&2
  exit 2 ;
fi
echo % Making Reg. Day schedule for $1 for $2 1>&2
echo % Making appointments every $3 minutes 1>&2
echo "\documentstyle[12pt]{article}

\setlength{\topmargin}{-.53in}
\setlength{\oddsidemargin}{-.03in}
\setlength{\textwidth}{6.36in}
\setlength{\textheight}{9in}
\setlength{\parskip}{\medskipamount}

\nofiles

\begin{document}

\begin{center}
{\Large Registration Day $1\\\ Appointments for $2}
\end{center}

"
interval=$3;
shift ; shift ; shift
while test "$1"
do
  echo % Making appointments from $1 to $2 1>&2
  start_hour=`expr $1 : '\(.*\):.*'`
  start_minute=`expr $1 : '.*:\(.*\)'`
  end_hour=`expr $2 : '\(.*\):.*'`
  end_minute=`expr $2 : '.*:\(.*\)'`
  shift ; shift
  echo '\noindent'
  until test $start_hour$start_minute -gt $end_hour$end_minute
  do
    start_minute=`expr $start_minute + 0`
    if test $start_minute -lt 10
    then
      start_minute=0$start_minute
    fi
    echo "$start_hour:$start_minute\hrulefill\ \\\ "
    start_minute=`expr $start_minute + $interval`
    if test $start_minute -ge 60
    then
      start_minute=`expr $start_minute - 60`
      start_hour=`expr $start_hour + 1`
      if test $start_hour -gt 12
      then
        start_hour=`expr $start_hour - 12`
      fi
    fi
  done
  echo '

'
done
echo '\end{document}
'
