#!/usr/bin/perl # Parseform Sub-Routine. # Usage: drop sub into CGI script. When you need to parse the form, # do a &parseform; . The data is stored in the %FORM hash. To access, # use the form $FORM{'field_name'} . # From http://www.cgi.tj/ sub parseform { if ($ENV{'REQUEST_METHOD'} eq 'GET') {@pairs = split(/&/, $ENV{'QUERY_STRING'});} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); } else { print "Content-Type: text/html\n\n"; print "

Bad or unknown request method.

\n"; exit(0); } foreach $pair (@pairs) { local($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s///g; $FORM{$name} = $value; } } &parseform; print "Content-Type: text/html\n\n"; print ""; print "
"; print ""; print "
"; print ""; #print ""; print ""; print "
Macros:
"; print ""; print "
"; print ""; print "
"; if ($FORM{'speechtext'} eq "") { if($FORM{'speechmacro'} eq "") { &speakit($emotion); } else { &speakit("$emotion$FORM{'speechmacro'}"); } } else { &speakit("$emotion$FORM{'speechtext'}"); # speakit($FORM{'speechtext'}); } # Send the data to zaza2 sub speakit { my ($speechtext) = @_; use strict; use Socket; my ($remote, $port, $iaddr, $paddr, $proto, $line); $remote = 'zaza2.exhibits.thetech.org'; $port = 101; # speech port if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') } die "No port" unless $port; $iaddr = inet_aton($remote) || die "no host: $remote"; $paddr = sockaddr_in($port, $iaddr); $proto = getprotobyname('tcp'); socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; connect(SOCK, $paddr) || die "connect: $!"; print "Speech data: $speechtext"; print SOCK "$speechtext\r\n"; sleep 1; close (SOCK) || die "close: $!"; }