#!/bin/csh
#
# PostScript business card printing script
#
# Authors: Roger Myers and Andrew Rogers
#
set OUT = "| lp"			# default output file or pipe
set DIR = "."				# directory where boilerplate lives

echo "Business card printer version 1.0"
echo ""
echo "Free business card printer by Roger Myers of CRS Printing"
echo "Route 3 Box 269-D, Philippi, WV  26416"
echo ""
echo "(Converted to csh and enhanced by Andrew Rogers)"
echo ""
echo "Enter your business card information below and this program will"
echo "generate a PostScript file that you can send to your laser printer"
echo "to print the business cards.  It will print enough pages of business"
echo "cards to fulfill your request and (optionally) tic marks for you to"
echo "use when cutting out your cards."
echo ""

# prompt user for business card information

echo -n "Enter your name: "
set FULLNAME = $<
echo -n "Enter your title: "
set TITLE = $<
echo -n "Enter your company's name: "
set COMPANY = $<
echo -n "Enter your street address: "
set STREET1 = $<
echo -n "Enter your city-state-ZIP: "
set STREET2 = $<
echo -n "Enter your telephone number: "
set TELEPHONE = $<
echo -n "Enter your FAX number or E-mail address: "
set FAX = $<

# prompt user for information regarding output format

echo -n "How many business cards would you like? "
set C = $<
@ COPIES = ( $C + 11 ) / 12
if ($COPIES <= 0) set COPIES = 1
echo $COPIES "page(s) of business cards will be printed."
set G = "Y"
echo -n "Do you want tic marks for cutting (Y/N; default: $G)? "
set GRID = $<
if ("$GRID" == "") set GRID = $G
set TMPFILE = /tmp/$$

echo -n "Name of output file or pipe (default: '$OUT')? "
set OUTFILE = $<

if ("$OUTFILE" == "") set OUTFILE = "$OUT"
# if output "file" is really a pipe, direct output to temp file
if ("$OUTFILE" =~ \|*) then
	set PIPE = "$OUTFILE"
	set OUTFILE = $TMPFILE
endif

# tweak some of the fields as necessary for nicest looking output

# if first address line is blank, move second to first
if ("$STREET1" == "") then
	set STREET1 = $STREET2
	set STREET2 = ""
endif

# if FAX number supplied, preface with "FAX:" if needed
if ("$FAX" != "" && "$FAX" !~ *[\!@]* && "$FAX" !~ [Ff][Aa][Xx]* ) set FAX = "FAX: $FAX"

# print the PostScript definitions and boilerplate

echo '%\!' > $OUTFILE
echo "($FULLNAME)" "($TITLE)" >> $OUTFILE
echo "($COMPANY)" "($STREET1)" "($STREET2)" >> $OUTFILE
echo "($TELEPHONE)" "($FAX)" >> $OUTFILE
cat $DIR/buscard.ps >> $OUTFILE
echo "do_cards" >> $OUTFILE
if ("$GRID" =~ [Yy]* ) then
	echo "grid" >> $OUTFILE
endif
echo "/#copies" $COPIES "def" >> $OUTFILE
echo "showpage" >> $OUTFILE


# if output "file" was a pipe, cat temp file through pipe and delete it

if ("$OUTFILE" == "$TMPFILE") then
	eval `echo "(cat $TMPFILE $PIPE)"`
	rm -f $TMPFILE
endif