#!/usr/bin/perl -Tw # # This is John Chambers' CGI script to take the output of the # saying command and deliver it as a web page. Look for the # Sayings file for the data used by these programs. $| = 1; ($P = $0) =~ s".*/""; $V = $ENV{"V_$P"} || 1; $inHTML = 1; print "Content-type: text/html\n\n"; print "\n"; print "Saying of the day from " . `hostname` . "\n"; print "\n"; $looping = ($0 =~ /s$/) ? 100 : 1; $ENV{"PATH"} = '.:' . $ENV{"PATH"}; $cmd = 'saying'; $cwd = `pwd`; print "CWD: $cwd
\n" if $V>2; $pth = `which $cmd`; print "CMD: $pth
\n" if $V>2; if ($n = $ENV{'PATH_INFO'}) { $n =~ s/\D+//g; print "Saying $n:

\n"; $cmd .= " $n"; } loop: while ($looping) { @txt = `$cmd`; print "Cookie $looping:
\n" if $V>1; for $line (@txt) { $line =~ s/[\s\r]+$//; print "
Line: \"$line\"
\n" if $V>1; ($pfx,$msg) = ($line =~ /^(\|*) ?(.*)$/); if ($pfx eq '|') { # HTML? # } else { # Plain text. if ($wasHTML) { # We're in a

 section
				print "
"; $inHTML = 1; $wasHTML = 0; } elsif ($wasHTML = $inHTML) { print "
";
				$inHTML = 0;
			}
		}
		if ($inHTML) {
		#	$msg =~ s/^\s*//;
			$msg = "

" unless $msg; } print "\t$msg\n"; } if ($wasHTML) { print "

"; $inHTML = 1; $wasHTML = 0; } if (--$looping > 0) { print "

\n"; sleep 10; } } print "\n"; exit 0;