#!/bin/csh -e
#mail a directory of shar files to someone
#USAGE: (from the shar file directory):
#    send-emaildist <address>

if ( ! $#argv) then
    echo No destination address given; exit 1
endif

if ( ! ( -f EMAILDIST-README && -f Isabelle.aa ) ) then
    echo `pwd` is not an emaildist directory; exit 1
endif
set count=0
set total = `ls Isabelle.?? | wc -l`

if ( ! ${?MAILPROG} ) set MAILPROG = mail
$MAILPROG -s 'Distribution information' $1 < EMAILDIST-README
foreach file (Isabelle.??)
    @ count++
    echo Mailing $file '(' $count of $total ')'
    shar -e$total -n$count $file | $MAILPROG -s "File $count of $total" $1
    end
if ( $count == $total ) then
    echo Email distribution successfully sent to $1
else
    echo Email distribution to $1 failed: $count $total
endif
