Text File

#!/usr/local/bin/perl # gophertree v1.0 # Prints pretty indented listings of a Gopher menu tree # Copyright (C) 1992, Trustees of Michigan State University # # Modifications: # Original author unknown # 07/07/92 Boone Major conversion from gopherls # 08/14/92 Boone Fixes: # added code to allow command line limit on recursion # depth # quit indenting after 15 levels to avoid filling the # title field with spaces # changed to use IP address instead of hostname when # checking for off-host links; this should make # aliased machine names (e.g. gopher.someschool.edu) # work much better # Enhancements: # Added option to list only directories # Changed limit on number of items listed to apply to # all types except directories, instead of just # files; still no per-type limits though # Changed command line processing to use Getopts, # allowing better option processing # End Modifications

require "getopts.pl";

sub dokill { kill 9, if ; }

sub Opengopher { ++; local(,) = @_; = 'localhost' unless ;

= 2; = 1;

{'INT'} = 'dokill';

= 'S n a4 x8';

chop( = `hostname`);

(,,) = getprotobyname('tcp'); (,,) = getservbyname(,'tcp') unless =~ /^\d+$/;; (,,,,) = gethostbyname(); (,,,,) = gethostbyname();

= pack(, , , ); = pack(, , , );

# Make the socket filehandle. socket(S, , , ) || die $!;

# Give the socket an address. bind(S, ) || die $!;

# Call up the server. connect(S,) || die $!;

# Set socket to be command buffered. select(S); $| = 1; select(STDOUT);

}

sub GetList { local(, , , ) = @_; local(@dirx, , , , , , %i, ); &Opengopher(, ); print S "\n"; @dirx = <S>; close(S); = 0; foreach (@dirx) { last if /^\./; chop; chop; (, , , ) = split('\t', ); = substr(, 1); = substr(, 0, 1); = . ; = ""; = "File" if ( eq "0"); = "Dir" if ( eq "1"); = "Phone" if ( eq "2"); = "Error" if ( eq "3"); = "MacHqx" if ( eq "4"); = "PcHqx" if ( eq "5"); = "Uue" if ( eq "6"); = "Index" if ( eq "7"); = "Telnet" if ( eq "8"); = "Bin" if ( eq "9"); = "File" if ( eq "R"); = "TN3270" if ( eq "T"); = "File" if ( eq "e"); = "Ftp" if ( eq "f"); = "HTML" if ( eq "h"); = "Info" if ( eq "i"); = "Mail" if ( eq "m"); = "Sound" if ( eq "s"); = "Index" if ( eq "w"); = ;

= 1; if ((! ) && ( ne "1") && ({} > )) { = 0; = 1; } if ( eq "i") { = 0; } if ( && ( ne "1")) { = 0; } if () { write; }

if ({} eq "") { {} = unpack("L", (gethostbyname())[4]); }

if (( eq "1") && ({} eq {}) && (( != ) || ( != ""))) { = ; if ( < ) { .= ; } ++; if ( <= ) { &GetList(, , , ); } --; }

{}++; } if () { print " . . .\n"; --$-; } }

# ************************************************************************** # * Main # **************************************************************************

# Parse command line

&Getopts("b:l:dr:"); if ($#ARGV < 1) { print "Usage: gophertree [-d -bn -ln -rn] host port path\n"; exit(1); }

= = [0]; = = [1]; = ""; if ($#ARGV == 2) { = [2]; }

# Initialize some variables

(,,,,,,,,) = localtime(time); = +1 . "/" . . "/" . ;

$^ = 'TOP'; # Report header format $~ = 'STDOUT'; # Report body format = ""; # Goes in front of description to indicate treeness = 1; # How deep into the maze are we? {} = unpack("L", (gethostbyname())[4]);

# CHANGE--User-configurable defaults

= 15; # CHANGE--Where to break long lists $= = 55; # CHANGE--Lines per page = " "; # CHANGE--Amount to indent each new level = 15; # CHANGE--How far down before we quit indenting = 999; # CHANGE--How deep to go before "pruning" layers

# Stuff command line changes into the config variables

if () { = ; } if () { $= = ; } if () { = ; }

# Real work

&GetList(, , , ); exit(0);

# # Formats #

format TOP =

MSU Gopher Road Map Host: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Last Update: @<<<<<<< Page: @>> $%

Lev Name Type Destination --- ------------------------------------------ ------ ------------------------- .

format STDOUT = @>> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<< @<<<<<<<<<<<<<<<<<<<<<<<< .