#! /bin/tcsh -f
#

#! /bin/tcsh -f
#
# Usage:
#	codeprint2.csh outdir header infiles...
#
# Description:
#
# Version of ./codeprint2.csh, q.v., for use in the book.  No line numbers,
# page numbers, bigger font,
#

if ($1 == "-h") then
    echo "Usage:  codeprint2.csh outdir header infiles..."
    exit
endif

set subdir = $1
shift
set lhdr = $1
shift
foreach f ($*)

#   Uncomment any or all of the echo commands for debugging purposes.

#
# Number lines and untabify using emacs batch script.
#
#   echo "Processing $f, step 1"
    emacs -batch $f -l ~/projects/support/documentation/emacs/number-lines-batch.el \
	-f echo-lines-untabify >& /tmp/$f.tmp1

#
# Cat the header onto the front of the file, saving the result in a tmp file.
#
#   echo "Processing $f, step 2"
    emacs -batch /tmp/$f.tmp1 -l ~/emacs/lib/remove-fink-vars-line.el >& /dev/null
    cat ~/projects/support/documentation/code/hdr2-book.me /tmp/$f.tmp1 > /tmp/$f.tmp2

#
# Do the deed with troff.
#
#   echo "Processing $f, step 3, outputting to $subdir/$f-2c.ps"
    troff -me -dl"$lhdr" -df"$f" /tmp/$f.tmp2 | grops -l > $subdir/$f-2c.ps


#
# Delete or save the troff source file; normally it should be deleted.
#
#   echo "Processing $f, step 4"
#   Exchange commenting of the next line two lines to save .me troff file for
#   debugging purposes.
   rm /tmp/$f.tmp2
#   mv /tmp/$f.tmp2 $subdir/$f.lno2.me

#
# Remove the tmp.
#   echo "Processing $f, step 5"
    rm /tmp/$f.tmp1
#    if (-l ".#$f") rm -f ".#$f"

end
