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 / gophercat < prev    next >
Text File  |  1991-08-29  |  2KB  |  81 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. $ZeName = shift(@ARGV) || die "I need an argument\n";
  45.  
  46. open(GopherFile, "/tmp/.gopher") || die "You haven't run gsetup yet!";
  47.  
  48. $Firstline = <GopherFile>;
  49. ($CurrentHost, $Port, $Path) = split('\t',$Firstline);
  50. &Opengopher( $CurrentHost, $Port);
  51.  
  52. print S "$Path\n";
  53.  
  54. while (<S>) {
  55.     chop;
  56.     chop;
  57.     ($ObjName, $Path, $Host, $Port) = split('\t', $_, 6);
  58.     $Name = substr($ObjName, 1);
  59.     $Obj  = substr($ObjName, 0, 1);
  60.  
  61.     if ($ZeName eq $Name) {
  62.     $ZePath = $Path;
  63.     $ZeHost = $Host;
  64.     $ZePort = $Port;
  65.     }
  66.  
  67. }
  68.  
  69. close S;
  70.  
  71. &Opengopher( $ZeHost, $ZePort);
  72.  
  73. print S "$ZePath\r\n";
  74.  
  75. while (<S>) {
  76.     chop;
  77.     chop;
  78.     print;
  79.     print "\n";
  80. }
  81.