#!/usr/local/bin/perl # Gateway from WWW to the Geography server at U Michigan # Copyright 1992 Xerox. All rights reserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # Jim Davis, Nov 17 1992 # To do: # 1) Parse the returned info so as to display more neatly. # (See documentation at end of file its format.) # 2) Handle case where multiple places match supplied name # 3) Handle case where no place matches supplied name. # This expects one argument, a document ID. The search keywords # are sent to the Geography server, the "pathname" is ignored. # e.g. /geography/ignored/whocares?ithaca,ny => ithaca,ny # As an extra bonus feature, if the first arg has no question marks # then the entire arg line is passed to the server. This is # convenient when you call this from the shell rather than from WWW. if ($#ARGV == -1) { die "Usage: geography-gateway [WWW-DOCUMENT-ID | location]\ An example WWW document id is /geography?washington,dc If calling from shell, omit the /geography? part.\nStopped";} $usage = "\n\ Geography Server\n\

Type geographic name in Index.

\n\ "; # for debugging # print "\n"; # print "ARGV = $#ARGV\n"; # for ($i = 0; $i < $#ARGV+1; $i++) { # print "Arg $i is $ARGV[$i]\n";} # print ""; # exit; @parts=split('/', $ARGV[0]); # separate pathname from keywords. $last = $parts[$#parts]; # the last path component has keys $i=index($last,"?"); # are there any keywords in there? if ($i == -1) {@keywords = @ARGV;} # none, probably called from shell else {@keywords=split('\?', substr($last,$i)); $parts[$#parts] = substr($last,0,$i);} # if no keywords, tell user how to type them. if ($#keywords == -1) { print $usage; exit; }; # debugging # print "\n # parts are @parts\n # keywords are @keywords\n # \n"; # exit; # otherwise contact the server $host = "martini.eecs.umich.edu"; $port = 3000; $sockaddr = 'S n a4 x8'; # packing format $hostname = `hostname`; # where I am calling from chop($hostname); # get rid of trailing CR ($name, $aliases, $type, $len, $myaddr) = gethostbyname($hostname); $here = pack($sockaddr, 2, 0, $myaddr); ($name, $aliases, $type, $len, $destaddr) = gethostbyname($host); #print ("Name = ", $name ," " addr = ", $destaddr, "\n"); if ($destaddr eq "") {die "No such host: $host. Stopped";} $there= pack($sockaddr, 2, $port, $destaddr); ($name, $aliases, $protocol) = getprotobyname('tcp'); socket($S, 2, 1, $protocol) || die "socket: $!"; bind ($S, $here) || die "bind: $!"; connect ($S, $there) || die "connect: $!"; select($S); $| = 1; # force output print (@keywords ,"\n"); print "quit\n"; select(STDOUT); print "\n"; while (<$S>) { print;} print "\n"; select($S); exit; # This is the format of info returned by the geo server. # in case you decide you want to parse it. # 0 # 1 # 2 # 3 # A # E # F # L # P <1980 census population> # R # T