home *** CD-ROM | disk | FTP | other *** search
/ ftp.muug.mb.ca / 2014.06.ftp.muug.mb.ca.tar / ftp.muug.mb.ca / pub / src / gopher / gopher1.01 / misc / shell-utils / gopherls < prev    next >
Text File  |  1991-08-29  |  2KB  |  77 lines

  1. #!/usr/local/bin/perl
  2.  
  3. sub dokill {
  4.     kill 9,$child if $child;
  5. }
  6.  
  7. sub Opengopher {
  8.  
  9.     local($them,$port) = @_;    
  10.     $them = 'localhost' unless $them;
  11.  
  12.     $AF_INET = 2;
  13.     $SOCK_STREAM = 1;
  14.  
  15.     $SIG{'INT'} = 'dokill';
  16.  
  17.     $sockaddr = 'S n a4 x8';
  18.  
  19.     chop($hostname = `hostname`);
  20.  
  21.     ($name,$aliases,$proto) = getprotobyname('tcp');
  22.     ($name,$aliases,$port) = getservbyname($port,'tcp')
  23.     unless $port =~ /^\d+$/;;
  24.     ($name,$aliases,$type,$len,$thisaddr) = gethostbyname($hostname);
  25.     ($name,$aliases,$type,$len,$thataddr) = gethostbyname($them);
  26.  
  27.     $this = pack($sockaddr, $AF_INET, 0, $thisaddr);
  28.     $that = pack($sockaddr, $AF_INET, $port, $thataddr);
  29.  
  30.     # Make the socket filehandle.
  31.     socket(S, $AF_INET, $SOCK_STREAM, $proto) || die $!;
  32.  
  33.     # Give the socket an address.
  34.     bind(S, $this) || die $!;
  35.  
  36.     # Call up the server.
  37.     connect(S,$that) || die $!;
  38.  
  39.     # Set socket to be command buffered.
  40.     select(S); $| = 1; select(STDOUT);
  41.  
  42. }
  43.  
  44. while ($arg = shift(@ARGV)) {
  45.     if ($arg eq "-l") {
  46.         $LongFlag = 1;
  47.     }
  48.     }
  49.  
  50. open(GopherFile, "/tmp/.gopher") || die "You haven't run gsetup yet!";
  51.  
  52. $Firstline = <GopherFile>;
  53. ($CurrentHost, $Port, $Path) = split('\t',$Firstline);
  54. &Opengopher( $CurrentHost, $Port);
  55.  
  56. print S "$Path\n";
  57.  
  58. while (<S>) {
  59.     chop;
  60.     chop;
  61.     ($ObjName, $Path, $Host, $Port) = split('\t', $_, 6);
  62.     $Name = substr($ObjName, 1);
  63.     $Obj  = substr($ObjName, 0, 1);
  64.  
  65.     if ($LongFlag) {
  66.     print "$Host\t$Port\t";
  67.     }
  68.  
  69.     print "$Name" if ($ObjName ne ".");
  70.     print "/" if ($Obj eq "1");
  71.     print "." if ($Obj eq "0");
  72.     print " <?>" if ($Obj eq "7");
  73.  
  74.  
  75.     print "\n";
  76. }
  77.