head     1.3;
branch   ;
access   ;
symbols  ;
locks    ; strict;
comment  @# @;


1.3
date     95.03.07.14.18.02;  author yonah;  state Exp;
branches ;
next     1.2;

1.2
date     94.11.15.03.17.59;  author nocturne;  state Exp;
branches ;
next     1.1;

1.1
date     94.11.15.03.13.44;  author nocturne;  state Exp;
branches ;
next     ;


desc
@geographic nameserver stuff
@


1.3
log
@*** empty log message ***
@
text
@#!/usr/athena/bin/perl
# $Id: geo,v 1.2 1994/11/15 03:17:59 nocturne Exp $

require 'our-chat2.pl';
require 'perlwww.pl';

$query = join(' ', @@ARGV) if $ARGV[0];
&do_geo($query);

sub listen {
        local($secs) = @@_;
        local($return,$tmp) = "";
        while (length($tmp = &chat'expect($secs, '(.|\n)+', '$&'))) {
                print $tmp if $trace;
                $return .= $tmp;
        }
        $return;
}
# 0 <city name>
# 1 <county FIPS code> <county name>
# 2 <state/province abbreviation> <state/province name>
# 3 <nation abbreviation> <nation name>
# A <telephone area code>
# E <elevation in feet above mean sea level>
# F <feature code> <feature name>
# L <latitude DD MM SS X> <longitude DDD MM SS X>
# P <1980 census population>
# R <remark>
# T <time zone>
# Z <postal ("ZIP") code>

sub do_geo {
    local($request)=@@_;
    local($foo, $bar, $rest, $qreq, @@els);
    $request =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig;
    $request =~ s/\+/ /g;

    if(!$request){
        print("Content-Type: text/html\n\n");
        # &main'MIME_header('ok', 'text/html'); # HTTP/1.0 compliance

        print <<"EndOfInfo";
<head>
<title>Geographic Nameserver</title>
<h1><img align=top src="bitmaps/globe.xbm">
  Enter the name of the place you want to look up</h1>

For example, enter "<a href="geo?cambridge,+ma">cambridge, ma</a>" to
look up Cambridge, Massachusetts.  If you enter just
"<a href="geo?cambridge">cambridge</a>", you will get information on
all towns called Cambridge.<p> This server contains mostly information
on locations within the US.  It uses the information from the
geographic nameserver database on martini.eecs.umich.edu<p>

<isindex>
EndOfInfo
        return;
    }

    &chat'open_port('martini.eecs.umich.edu', 3000)
        || die "open: $!";

    while (!/Geographic/) { $_ = &listen(5);}
    &chat'print("$request\n");
    $_=&listen(3);
    split(/\n/);

    if ($#_) {
        print("Content-Type: text/html\n\n");        
        # &main'MIME_header('ok', 'text/html');   # HTTP/1.0 compliance
	print("<h1>Geographic NameServer Query:  \"$request\"</h1><pre>\n");

        foreach $dataline (@@_){
            @@els = split(/[ ]+/, $dataline);
            $foo =shift(@@els);
            if($foo=~/0/){
		$rest = join(' ',@@els);
		chop($rest);
		print("\nLocation Name:  $rest\n");
	    }
            if($foo=~/1/){
		$bar = shift(@@els);
		$rest = join(' ', @@els);
		chop($rest);
		print("County:         $rest ($bar)\n");
	    }
            if($foo=~/2/){
		$bar = shift(@@els);
		$rest = join(' ', @@els);
		chop($rest);
		print("State/Province: $rest ($bar)\n");
            }
            if($foo=~/3/){
		$bar = shift(@@els);
		$rest = join(' ', @@els);
		chop($rest);
		print("Country:        $rest ($bar)\n");
            }
            if($foo=~/A/){
		$rest = join(' ', @@els);
		chop($rest);
		print("Area Code:      $rest\n");
            }
            if($foo=~/E/){
		$rest = join(' ', @@els);
		chop($rest);
		print("Elevation:      $rest\n");
            }
            if($foo=~/L/){
		print("Latitude:       $els[0] $els[1]' $els[2]\" $els[3]\n");
		print("Longitude:      $els[4] $els[5]' $els[6]\" $els[7]\n");
            }
            if($foo=~/P/){
		print("Population:     $els[0]\n");
            }
            if($foo=~/T/){
		print("Time Zone:      $els[0]\n");
            }
            if($foo=~/Z/){
		print("Zip Code:       $els[0]\n");
            }
            if($foo=~/R/){
		$rest = join(' ', @@els);
		print("Comment:            $rest\n");
            }
        }
        print "</pre><isindex>";
    } else {
        print("Content-Type: text/html\n\n");
        # &main'MIME_header('ok', 'text/html');   # HTTP/1.0 compliance
	print("<h1>Geographic NameServer Query:  \"$request\"</h1>\n");
        print "Sorry, no matches found.<p>\n";
        if ($request =~ s/([^,]) ([^ ]+)$/\1, \2/) {
           $qreq = &perlwww'printable($request);
           print "Maybe you mean \"<a href=\"geo?$qreq\">$request</a>\"?<p>\n";
        }
    }
    &chat'print("quit\n");
}

1;
@


1.2
log
@fixed to use a fixed version of chat2.pl that works under solaris
@
text
@d1 2
a2 2
#!/afs/athena/contrib/perl/p
# $Id: geo,v 1.1 1994/11/15 03:13:44 nocturne Exp nocturne $
@


1.1
log
@Initial revision
@
text
@d2 1
a2 1
# $Id: geo.pl,v 1.3 1994/02/11 18:49:50 bert Exp $
d4 1
a4 1
require 'chat2.pl';
@
