#!/usr/local/bin/perl -s # A Perl script to send form letters by either email or latex. # File: send-letters # Author: Peter Lee # # Command-line arguments: # # send-letters [-email] [-tex] database letter comments1 comments2 ... # # where "database" is a database file containing the list of papers, # "letter" is the file containing the form letter, and the "comments"n # files are the files containing the reviewers' comments. Each "comments"n # file must named after the paper number (eg, the comments for paper #16 # must be named 16). Such files can be created by the "munge" program. # # The database file must have the following format: # #Number 1 #Title Space Travel without Seasickness #Authors Peter Lee #Email petel@cs.cmu.edu #Address Department of Computer Science \\ Carnegie Mellon University \\ Pittsburgh, PA 15213-3891 #end # #Number 2 #Title Seasickness without Space Travel #Authors Ron Cytron #Email cytron@kato.wustl.edu #Address Department of Computer Science \\ Washington University \\ Campus Box 1045 \\ St. Louis, MO 63130 #end # # The format is very strict --- in particular, I don't think the blank line # between each entry is optional. (The program does some syntax-checking.) # # The letter file may contain and fields, which # will be filled in appropriately. # The -email option causes each form letter to be sent via email. # The -tex option causes each form letter to be generated by latex and printed. $num_papers = 32; # Read the paper database file open(DB, shift); while(<DB>) { if (s/^Number[ \t]+([0-9]+)[ \t]*\n/$1/i) { $i = int($1); } else { print "Missing number field, $i\n"; exit 1; } $_ = <DB>; if (s/^Title[ \t]+(.+)[ \t]*\n/$1/i) { $title[$i] = $1; } else { print "Missing title field, $i\n"; exit 1; } $_ = <DB>; if (s/^Authors[ \t]+(.+)[ \t]*\n/$1/i) { $authors[$i] = $1; } else { print "Missing author field, $i\n"; exit 1; } $_ = <DB>; if (s/^Email[ \t]+(.+)[ \t]*\n/$1/i) { $email[$i] = $1; if ($email[$i] eq '---') { print STDERR "No email address for $authors[$i]\n"; } } else { print "Missing email field, $i\n"; exit 1; } $_ = <DB>; if (s/^Address[ \t]+(.+)[ \t]*\n/$1/i) { $address[$i] = $1; } else { print "Missing address field, $i\n"; exit 1; } $_ = <DB>; if (!/^end/i) { print "Missing author field, $i\n"; exit 1; } $_ = <DB>; } close(DB); if ($email) { # Read the form letter. if ($letterfile = shift) { open(LETTER,$letterfile); $line = 0; while (<LETTER>) { $letter[$line++] = $_; } } else { print "No form letter file specified\n"; exit 1; } close(LETTER); # Now open each reviewer file and construct a letter for each author. while ($comments = shift) { if (!($email[$comments] eq '---')) { print STDERR "Sending mail to $email[$comments]\n"; open(MAIL,"| mail $email[$comments]"); for ($i=0; $i<$line; $i++) { $_ = $letter[$i]; s/<author>/$authors[$comments]/; s/<title>/$title[$comments]/; print MAIL; } open(COMMENTS,$comments); while(<COMMENTS>) { print MAIL; } print MAIL ".\n"; close(MAIL); } } } if ($tex) { # Read the form letter. if ($letterfile = shift) { open(LETTER,$letterfile); $line = 0; while (<LETTER>) { $letter[$line++] = $_; } } else { print "No form letter file specified\n"; exit 1; } close(LETTER); # Now open each reviewer file and construct a letter for each author. while ($comments = shift) { print STDERR "\n******** Writing letter to $authors[$comments] ********\n\n"; open(TEXFILE,">letter$$.tex"); for ($i=0; $i<$line; $i++) { $_ = $letter[$i]; s/<author>/$authors[$comments]/; s/<title>/$title[$comments]/; s/<address>/$authors[$comments]\\\\$address[$comments]/; print TEXFILE; } close(TEXFILE); system("/usr/local/bin/latex letter$$.tex"); system("/usr/local/bin/dvips letter$$"); system("/usr/bin/rm letter$$.*"); open(TEXTFILE,"|/usr/local/bin/enscript -b'Reviewer comments'"); open(COMMENTS,$comments); while(<COMMENTS>) { print TEXTFILE; } close(TEXTFILE); } }