#!/usr/local/bin/perl # # NAME: WhatsForDinner (formerly 'menu') # AUTHOR: Michael J. Radwin, Adam Doppelt # DESCR: display today's UFS menu # MODIFIED: $Id: WhatsForDinner,v 2.6 1997/04/09 13:49:27 mjr Exp $ # require 'getopts.pl'; # configuration parameters $pname = 'WhatsForDinner'; $webget = '/cs/bin/lynx'; # lynx is faster than webget $webget_opts = '-source'; $zwrite = '/cs/bin/zwrite'; #$mail = '/usr/local/bin/mail'; $mail = '/usr/bin/mail'; $url = "http://www.netspace.org/herald/daylink/menu.f.html"; #$header_tag = '
]*>\s*/\0/ig; # paragraph markers == meal delimiters s/<[^>]*>//g; # ignore all other tags s/ / /g; # fix html entities - spaces s/&/&/g; # and ampersands # support all entities? http://www.uni-passau.de/~ramsch/iso8859-1.html s/&([EeIiOo])grave;/pack("c", ord($1)+131)/ge; # there's a pattern s/&(Uu)grave;/pack("c", ord($1)+132)/ge; # here... can you s/&(Aa)grave;/pack("c", ord($1)+127)/ge; # see what it is? s/&([EeIiOoYy])acute;/pack("c", ord($1)+132)/ge; # of course, it's not s/&(Uu)acute;/pack("c", ord($1)+133)/ge; # consistent. Bastards. s/&(Aa)acute;/pack("c", ord($1)+128)/ge; s/&([EeIiOo])circ;/pack("c", ord($1)+133)/ge; s/&(Uu)circ;/pack("c", ord($1)+134)/ge; s/&(Aa)circ;/pack("c", ord($1)+129)/ge; s/&([EeIiOoy])uml|die;/pack("c",ord($1)+134)/ge; s/&(Uu)uml|die;/pack("c", ord($1)+135)/ge; s/&(Aa)uml|die;/pack("c", ord($1)+130)/ge; $menu .= $_; } # print out date of menu so the user can see if the info is current. while(
's on weekends. Ignore 'em. next if $meal =~ /^\s*$/; undef(@matching); # clear last meal's matches $lookslike = ''; if (!$opt_q) { $found = !@regexps; foreach $pat (@regexps) { if ($meal =~ /($pat)/i) { push(@matching, $1); $found = 1; } } next if $opt_s && !$found; } &setup_output unless $already_setup; if (!$opt_q && @matching) { #print STDOUT "Looks like UFS is serving up some: "; #print STDOUT join(", ", @matching), "\n"; $lookslike = $lookslike_tag . join(", ", @matching); } write; print STDOUT "\n"; } if ($already_setup && $opt_m) { print STDOUT "\nLove,\n$pname\n"; } elsif (!@menu && !$opt_m) { print STDOUT "Error: no meals listed in today's BDH.\n"; } close(STDOUT); exit(0); # if they want to mail the results, change STDOUT to pipe to the mail # program. sub setup_output { if ($opt_z) { open(STDOUT, "| $zwrite $ENV{'LOGNAME'}") || die "$pname: failed to redirect STDOUT: $!\n"; select(STDOUT); $| = 1; # make unbuffered } elsif ($opt_m) { open(STDOUT, "| $mail -s $pname $opt_m") || die "$pname: failed to redirect STDOUT: $!\n"; select(STDOUT); $| = 1; # make unbuffered print STDOUT "Dear $opt_m,\n\n"; } if (defined($story_appeared)) { print STDOUT $story_appeared, "\n"; } $already_setup = 1; } # this is a silly use of perl's format feature. Make the menu # paragraphs fit nicely in 74 columns and place line-breaks where # convenient. Come to think of it, this whole program is silly. format STDOUT = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ $lookslike ~~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $meal .