#!/bin/sh # /******************* self documentation **********************/ DOC () { echo ' LETTER - an automatic generator for letters letter address-file(s) Note: letter will read $HOME/.letterrc for information A typical address file can have the following addresses Dr. T. Goodman Dept of Comput \& Appl Math Rice University Houston, TX 77005--1892 Prof. V. Goodwoman Dept of Mathematics Purdue University W. Lafaette, IN 47907 A $HOME/.letterrc file can be name = YourName email = YourEmail officephone = Your Phone fax = Your Fax homephone = Your Home Phone mobilephone = Your Mobile Phone web = Your Web Address address= Your Address (e.g. Department \\ School \\ ... ) ' } # /**************** end self doc ********************************/ # Author: Seongjai Kim November-12-1996 case $# in 0) DOC 1>&2; exit 1 ;; *) FILES=$* ;; esac LETTERRC="$HOME/.letterrc" DATE=`date '+%D'` NAME=YourName EMAIL=YourEmail OFFICEPHONE=YourOfficephone FAX=YourFax HOMEPHONE=YourHomephone MOBILEPHONE=YourMobilephone WEB=YourWEB ADDRESS=YourAddress POSITION=YourPosition SINCERELY="Sincerely Yours," if test -f $LETTERRC; then NAME= ; EMAIL= ; OFFICEPHONE= ; FAX= ; HOMEPHONE= ; MOBILEPHONE= ; WEB= ; ADDRESS=; POSITION=; ARGS="`cat $LETTERRC`" ARGS="`echo $ARGS | sed -e 's/=/=\ /g' -e 's/\ =/=/g' -e 's/\#\ /\#/g'`" for term in $ARGS; do case $term in na*=) id=na ;; em*=) id=em ;; of*=) id=of ;; fa*=) id=fa ;; ho*=) id=ho ;; mo*=) id=mo ;; we*=) id=we ;; ad*=) id=ad ;; po*=) id=po ;; si*=) SINCERELY=; id=si ;; *=|\#*) id=xx ;; *) case $id in na) NAME="$NAME $term" ;; em) EMAIL="$EMAIL $term" ;; of) OFFICEPHONE="$OFFICEPHONE $term" ;; fa) FAX="$FAX $term" ;; ho) HOMEPHONE="$HOMEPHONE $term" ;; mo) MOBILEPHONE="$MOBILEPHONE $term" ;; we) WEB="$WEB $term" ;; ad) ADDRESS="$ADDRESS $term" ;; po) POSITION="$POSITION $term" ;; si) SINCERELY="$SINCERELY $term" ;; xx) ;; esac ;; esac done # the following is for erasing the fisrt empty spaces. NAME="`echo $NAME`" EMAIL="`echo $EMAIL`" OFFICEPHONE="`echo $OFFICEPHONE`" FAX="`echo $FAX`" HOMEPHONE="`echo $HOMEPHONE`" MOBILEPHONE="`echo $MOBILEPHONE`" WEB="`echo $WEB`" ADDRESS="`echo $ADDRESS`" POSITION="`echo $POSITION`" SINCERELY="`echo $SINCERELY`" fi for SRC in $FILES; do if test -f $SRC; then OUT=${SRC}_Let.tex CE=; CO=; CF=; CH=; CM=; CW=; CP=; CS= if test "$EMAIL" = ""; then CE='%' fi if test "$OFFICEPHONE" = ""; then CO='%' fi if test "$FAX" = ""; then CF='%' fi if test "$HOMEPHONE" = ""; then CH='%' fi if test "$MOBILEPHONE" = ""; then CM='%' fi if test "$WEB" = ""; then CW='%' fi if test "$POSITION" = ""; then CP='%' fi echo "%% Automatic generation for letters.... \documentclass[12pt]{article} \usepackage{latexsym,amssymb,amsmath} \usepackage{graphicx} \usepackage{myletter,epsfig,here} \pagestyle{empty} %%% includegraphics %\pagestyle{myheadings} %\Taller %\taller %\shorter" > $OUT echo " \begin{document} %\large %\parskip=6pt %\parindent=0pt \def\order{0} \baselineskip=1.1\normalbaselineskip " >> $OUT if test -f contents.tex; then echo '\input{contents.tex}' >> $OUT else echo '\def\contents{You should define \underline{\tt contents} in the file named \underline{\tt contents.tex}.}' >> $OUT fi echo " %%%%%%%%%%%%%% USER DEFINITION %%%%%%%%%%%%%%%%%%%%%%%%%%%% \sincerely{$SINCERELY} \sender{$NAME} $CE\email{$EMAIL} $CO\officephone{$OFFICEPHONE} $CF\fax{$FAX} $CH\homephone{$HOMEPHONE} $CM\mobilephone{$MOBILEPHONE} $CW\web{$WEB} $CP\position{$POSITION} %%%%%%%%%%%%%% END DEFINITIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%% \def\me{%\vglue-.3in \senderadd $ADDRESS \endsenderadd } \def\Dear{\vskip.15in\noindent Dear }" >> $OUT echo "\def\DATE{$DATE} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% " >> $OUT cat /dev/null > temp00000 awk '{ if(NF != 0) { if($1 ~/^\\def/) print $0 >> "temp00000" else if($1 !~/^\%/){count++ line[count]=$0 if(count==1){nset++ if($1 ~ /^Prof|Dr|Mr.|Mrs.|Ms./){SIR = $1 " " $NF} else {SIR = "Sir/Madam"} } } } else{ if(count>0){ if(nset>=2) printf("%s\n","\\newpage") >> "temp00000" printf("%s{%s}\n","\\def\\order",nset) >> "temp00000" printf("%s\n","\\me\\Today\\add") >> "temp00000" for(i=1;i<=count;i++) print line[i] >> "temp00000" printf("%s %s%s\n", "\\endadd \\Dear",SIR,", \\vskip.1in") >> "temp00000" printf("%s\n%s\n","\\contents","\\letterend") >> "temp00000" printf("%s\n%s\n%s\n%s\n\n","\\ps","\\noindent\\DATE","\\ifx\\cc\\undefined\\else\\newline\\noindent \\cc\\fi","\\endps") >> "temp00000" } count=0 } } END{ if(count>0){ if(nset>=2) printf("%s\n","\\newpage") >> "temp00000" printf("%s\n","\\me\\Today\\add") >> "temp00000" for(i=1;i<=count;i++) print line[i] >> "temp00000" printf("%s %s%s\n", "\\endadd \\Dear",SIR,", \\vskip.1in") >> "temp00000" printf("%s\n%s\n","\\contents","\\letterend") >> "temp00000" printf("%s\n%s\n%s\n%s\n\n","\\ps","\\noindent\\DATE","\\ifx\\cc\\undefined\\else\\newline\\noindent cc: \\cc\\fi","\\endps") >> "temp00000" } }' $SRC cat temp00000 >> $OUT echo '\end{document}' >> $OUT /bin/rm temp00000 echo " $OUT : produced put \"\def\contents{......}\" into \"contents.tex\" ? vi $OUT tt $OUT " else echo "$SRC: no such file." 1>&2 DOC 1>&2 fi done