#!/bin/bash
#
# Write course outline from config file
#
declare CONFIG_FILE  # Defaults to course.conf; may be re-set on command line
declare OUTFILE      #             outline.tex

SYLLABUS_FILE=syllabus.tex
MESSAGES="&> /dev/null" # run quietly by default
declare VERBOSITY

PROG=$(basename $0)

function write_outline {
cat <<HEADER >>$OUTFILE
%% Generated automatically on $(date)
%% $COURSE Course information sheet, $TERM, $YEAR
%%
\documentclass[11pt]{article}

\pagestyle{empty}
\newcommand{\vp}{$\vphantom{\Big|}$}

HEADER
if [ "$CUSTOM_SIZE" = "yes" ]; then
cat <<MARGINS >>$OUTFILE
\setlength{\textwidth}{5.5in}
\setlength{\oddsidemargin}{0.5in}
\setlength{\topmargin}{-.5in}
\setlength{\textheight}{8.5in}

MARGINS
fi

cat <<EOF >>$OUTFILE
\begin{document}

\begin{center}
\textbf{$COURSE, Section $SECTION} \\\\
Course Information Sheet, $TERM Semester, $YEAR \\\\
Professor $INSTRUCTOR
\end{center}

\subsubsection*{Contact Information}

\noindent Office: $OFFICE Hall \\\\
Office Hours: $OFFICE_HOURS \\\\
Telephone: $TELEPHONE \\\\
email: \texttt{$EMAIL} \\\\
web: \verb+$WEB_URL+
\medskip

Office hours are for your benefit; please use them. $\ddot{\smile}$ If
you cannot make any of the times, see me or send email to make an
appointment. If you're having trouble, it's best to see me as soon as
possible. The sooner you talk to me, the easier it is to get you back
on track in the course.


\subsubsection*{Grading}

The course grade has four components: Problem sets, computer labs,
midterm tests~(3), and the final exam. Your course grade is
out of 1000~points.

\paragraph{Problem Sets}

Problem sets will be posted each Friday, and are due the following
Friday at the beginning of the lecture. Late problem sets will not be
accepted. Your best 10~problem sets will count for 15\%~of your course
grade.

\paragraph{Computer Labs}

There will be five computer labs during the term, which will count for
10\% of your course grade.

\paragraph{Midterm Exams}

There are three non-cumulative midterm exams, scheduled for 
$MIDTERM1; $MIDTERM2; 
and $MIDTERM3.
The best two test scores each count for 20\% of your grade; the
lowest score is worth~10\%. Midterms will be held in the evening. If
you have a midterm conflict due to an athletic event, illness, or a
family emergency, let me know immediately.

\paragraph{Final Exam}

The final exam, which is worth~30\% of the course grade, is
cumulative. The College has scheduled the final exam for 
$FINAL_EXAM.
\textbf{Do not make travel plans that conflict with the midterms or 
final exam!}

\subsubsection*{Academic Honesty}

Like all Holy Cross faculty, I strongly support the College's Policy on
Academic Honesty, which is detailed in the catalog. It is \textbf{your 
responsibility} to read and adhere to this policy. Plagiarism and cheating 
are serious academic offenses.

I encourage you to discuss the problem sets with each other.  However,
it is crucial that you write up your problem sets in your own words,
without outside assistance. Do not plagiarize other students' work, and
do not lend your ungraded work to classmates for any reason.

\subsubsection*{Outside Help}

Aside from office hours, there is a Calculus Workshop that provides
drop-in peer tutoring. It is open Sunday--Thursday, 7:00--9:00~PM, in
Swords~302. The workshop runs on a first-come, first-served
basis. Tutors are there to help you develop solutions to problems, not
to do your homework for you.

%%The Math Department maintains a list of math students who tutor for
%%hire. See Ms.~Gail Hadad, the department secretary, in Swords~322,
%%for information on hiring a tutor.

\subsubsection*{Meeting Schedule}

The following is the syllabus for the term. It is possible that this
schedule will change slightly, though in no event will we go faster
than advertized.

\vfill
\hspace*{-0.875in}
\input{$SYLLABUS_FILE}

\end{document}
EOF
} # end of write_outline

function outline_help {
    echo "Usage: $PROG [options]" >&1

if [ "$VERBOSITY" != "" ]; then
cat <<HELP

  Recognized options are:

    -f, --config
      Specify the configuration file (default is course.conf)

    -h, --help
      Print help message; accepts --verbose option.

    -o, --output
      Specify the output file (default is outline.tex)

    -v, --verbose
      Show output messages. Mostly useful if this script hangs silently.

HELP
else
    echo "  \"$PROG -v -h\" for detailed help"
fi
exit 0
} # End of outline_help

function compile_outline {
    if [ -f $OUTFILE ]; then
	mv -f $OUTFILE $OUTFILE~
    fi

    write_outline
    laps -Pamz -Pcmz $VERBOSITY $OUTFILE $MESSAGES
}

### main ###

# function parse_options {
# Command-line options start with "-"
while [ "$1" != "${1#"-"}" ]; do
    case "$1" in
 
    -f|--config)
	CONFIG_FILE="$2";
	shift; shift;
	;;

    -h|--help)
	outline_help # exit script
	;;

    -o|--output)
	OUTFILE="$2";
	shift; shift;
	;;

    -v|--verbose)
	MESSAGES=""
	VERBOSITY="-vv"
        shift;
        ;;
 
    *)
        shift;
        ;;
    esac
done

# set defaults if not already set
if [ "$OUTFILE" = "" ]; then
    OUTFILE=outline.tex
fi

if [ "$CONFIG_FILE" = "" ]; then
    CONFIG_FILE=course.conf
fi

# } # end of parse_options

source $CONFIG_FILE

compile_outline

# All branches have exited by now




