home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / alt / gopher / 1027 < prev    next >
Encoding:
Internet Message Format  |  1992-07-21  |  8.0 KB

  1. Path: sparky!uunet!wupost!ukma!widener!netnews.upenn.edu!msuinfo!news
  2. From: boone@convex.cl.msu.edu (Dennis Boone)
  3. Newsgroups: alt.gopher
  4. Subject: Gopher Road Map tool "gophertree"
  5. Keywords: tree listing road map gopher gophertree
  6. Message-ID: <1992Jul21.205327.13158@msuinfo.cl.msu.edu>
  7. Date: 21 Jul 92 20:53:27 GMT
  8. Sender: news@msuinfo.cl.msu.edu
  9. Organization: Michigan State University, East Lansing
  10. Lines: 245
  11.  
  12. This tool creates an indented listing of the files in a Gopher server.
  13. We feel that a listing like the one created by gophertree will be helpful
  14. to new users as they begin using Gopher.  Later, as they develop confidence,
  15. it becomes a useful index.  By default, the listing is set up for printing
  16. on standard letter paper, but the program is configurable.  A sample listing
  17. appears below.
  18.  
  19. Gophertree is a major modification of the gopherls tool found in the Gopher
  20. distribution.
  21.  
  22. Example output:
  23.  
  24. MSU Gopher Road Map                      Host: gopher.msu.edu
  25. Last Update: 7/21/92                                                Page:   1
  26.  
  27. Name                    Type    Destination
  28. --------------------------------------    -------    ------------------------------
  29. About Gopher                            Dir     serv2.cl.msu.edu
  30.   What is it? (under construction)      File    serv2.cl.msu.edu
  31.   Why do I need it? (under constructio  File    serv2.cl.msu.edu
  32.   Where can I get it? (under construct  File    serv2.cl.msu.edu
  33.   How do I use it? (under construction  File    serv2.cl.msu.edu
  34.   Who can I contact?                    File    serv2.cl.msu.edu
  35.   When was the last update?             File    serv2.cl.msu.edu
  36.   About MSU's Gopher                    File    serv2.cl.msu.edu
  37. Michigan State University               Dir     serv2.cl.msu.edu
  38.   Alumni Association                    Dir     serv2.cl.msu.edu
  39.     Up Front: MSU Trustees Help Direct  File    serv2.cl.msu.edu
  40.     In-Basket                           File    serv2.cl.msu.edu
  41.     National Alumni Board Officers 199  File    serv2.cl.msu.edu
  42.     MSU Alumni Magazine (Table of Cont  File    serv2.cl.msu.edu
  43.     Around Circle Drive                 File    serv2.cl.msu.edu
  44.     People/John Mueller: Oldies But Go  File    serv2.cl.msu.edu
  45.     People/Arthur Hills: Golf's Hottes  File    serv2.cl.msu.edu
  46.     People/Ingrid Jones: Can't Beat He  File    serv2.cl.msu.edu
  47.     People/Ivan Lahaie: In the Realm o  File    serv2.cl.msu.edu
  48.     People/Joan Sills: The World's Top  File    serv2.cl.msu.edu
  49.     People/Julie Dixon: Medicine Woman  File    serv2.cl.msu.edu
  50.     People/Wayne Fontes: NFL Coach of   File    serv2.cl.msu.edu
  51.     People/Harriette McAdoo: Defining   File    serv2.cl.msu.edu
  52.     Dow Gift Will Accelerate Composite  File    serv2.cl.msu.edu
  53.     Meet Merrily Dean Baker, MSU's A.D  File    serv2.cl.msu.edu
  54.     . . .
  55.   Campus Events & Sights                Dir     serv2.cl.msu.edu
  56.     About Campus Events & Sights        File    serv2.cl.msu.edu
  57.     Bulletins                           File    serv2.cl.msu.edu
  58.     Events                              Dir     serv2.cl.msu.edu
  59.       Search Everything                 Index   netsun.cl.msu.edu
  60.       Search May                        Index   netsun.cl.msu.edu
  61.       May                               Dir     serv2.cl.msu.edu
  62.       Search June                       Index   netsun.cl.msu.edu
  63.       June                              Dir     serv2.cl.msu.edu
  64.  
  65.  
  66. The program:
  67. ---------------------------------snip-------------------------------
  68. #! /bin/sh
  69. # This is a shell archive, meaning:
  70. # 1. Remove everything above the #! /bin/sh line.
  71. # 2. Save the resulting text in a file.
  72. # 3. Execute the file with /bin/sh (not csh) to create the files:
  73. #    gophertree
  74. # This archive created: Tue Jul 21 16:49:49 1992
  75. export PATH; PATH=/bin:$PATH
  76. if test -f 'gophertree'
  77. then
  78.     echo shar: will not over-write existing file "'gophertree'"
  79. else
  80. cat << \SHAR_EOF > 'gophertree'
  81. #!/usr/local/bin/perl
  82. # gophertree
  83. # Prints pretty indented listings of a Gopher menu tree
  84. # Copyright (C) 1992, Trustees of Michigan State University
  85. # Modifications:
  86. # Original author unknown
  87. # 07/07/92 Boone      Major conversion from gopherls
  88. # End Modifications
  89.  
  90. sub dokill
  91. {
  92.     kill 9,$child if $child;
  93. }
  94.  
  95. sub Opengopher
  96. {
  97.     $sockaddr++;
  98.     local($them,$port) = @_;    
  99.     $them = 'localhost' unless $them;
  100.  
  101.     $AF_INET = 2;
  102.     $SOCK_STREAM = 1;
  103.  
  104.     $SIG{'INT'} = 'dokill';
  105.  
  106.     $sockaddr = 'S n a4 x8';
  107.  
  108.     chop($hostname = `hostname`);
  109.  
  110.     ($name,$aliases,$proto) = getprotobyname('tcp');
  111.     ($name,$aliases,$port) = getservbyname($port,'tcp')
  112.     unless $port =~ /^\d+$/;;
  113.     ($name,$aliases,$type,$len,$thisaddr) = gethostbyname($hostname);
  114.     ($name,$aliases,$type,$len,$thataddr) = gethostbyname($them);
  115.  
  116.     $this = pack($sockaddr, $AF_INET, $sockaddr, $thisaddr);
  117.     $that = pack($sockaddr, $AF_INET, $port, $thataddr);
  118.  
  119.     # Make the socket filehandle.
  120.     socket(S, $AF_INET, $SOCK_STREAM, $proto) || die $!;
  121.  
  122.     # Give the socket an address.
  123.     bind(S, $this) || die $!;
  124.  
  125.     # Call up the server.
  126.     connect(S,$that) || die $!;
  127.  
  128.     # Set socket to be command buffered.
  129.     select(S); $| = 1; select(STDOUT);
  130.  
  131. }
  132.  
  133. sub GetList 
  134. {
  135.     local($CurrentHost, $Port, $Path, $indent) = @_;
  136.     local(@dirx, $Name, $Obj, $fname, $ftype, $fhost, $i);
  137.     &Opengopher($CurrentHost, $Port);
  138.     print S "$Path\n";
  139.     @dirx = <S>;
  140.     close(S);
  141.     $i = 0;
  142.     foreach (@dirx) 
  143.     {
  144.         last if /^\./;
  145.         chop; chop;
  146.         ($ObjName, $Path, $CurrentHost, $Port) = split('\t', $_);
  147.         $Name = substr($ObjName, 1);
  148.         $Obj = substr($ObjName, 0, 1);
  149.         $fname = $indent . $Name;
  150.         $ftype = "";
  151.         $ftype = "File" if ($Obj eq "0");
  152.         $ftype = "Dir" if ($Obj eq "1");
  153.         $ftype = "Phone" if ($Obj eq "2");
  154.         $ftype = "Error" if ($Obj eq "3");
  155.         $ftype = "MacHqx" if ($Obj eq "4");
  156.         $ftype = "PcHqx" if ($Obj eq "5");
  157.         $ftype = "Uue" if ($Obj eq "6");
  158.         $ftype = "Index" if ($Obj eq "7");
  159.         $ftype = "Telnet" if ($Obj eq "8");
  160.         $ftype = "Binary" if ($Obj eq "9");
  161.         $ftype = "File" if ($Obj eq "R");
  162.         $ftype = "TN3270" if ($Obj eq "T");
  163.         $ftype = "File" if ($Obj eq "e");
  164.         $ftype = "Ftp" if ($Obj eq "f");
  165.         $ftype = "HTML" if ($Obj eq "h");
  166.         $ftype = "Info" if ($Obj eq "i");
  167.         $ftype = "Mail" if ($Obj eq "m");
  168.         $ftype = "Sound" if ($Obj eq "s");
  169.         $ftype = "Index" if ($Obj eq "w");
  170.         $fhost = $CurrentHost;
  171.  
  172.         write if (($i < $breaklong) && ($Obj ne "i"));
  173.  
  174.         if (($Obj eq "1") && ($CurrentHost eq $firsthost) && 
  175.             (($Port != $firstport) || ($Path != ""))) 
  176.         {
  177.             &GetList($CurrentHost, $Port, $Path, $indent . $iadd);
  178.         }
  179.  
  180.         $i++ if ($Obj eq "0");
  181.         if ($i == 15) 
  182.         {
  183.             print("$indent. . .\n");
  184.             --$-;
  185.         }
  186.     }
  187. }
  188.  
  189. # **************************************************************************
  190. # * Main
  191. # **************************************************************************
  192.  
  193. # Parse command line
  194.  
  195.     if ($#ARGV < 1) 
  196.     {
  197.         print "Usage:  gophertree  host  port  path\n";
  198.         exit(1);
  199.     }
  200.  
  201.     $firsthost = $CurrentHost = $ARGV[0];
  202.     $firstport = $Port = $ARGV[1];
  203.     $Path = "";
  204.     if ($#ARGV == 2) 
  205.     {
  206.         $Path = $ARGV[2];
  207.     }
  208.  
  209. # Initialize some variables
  210.  
  211.     ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  212.     $today = $mon+1 . "/" . $mday . "/" . $year;
  213.  
  214.     $^ = 'TOP';         # Report header format
  215.     $~ = 'STDOUT';      # Report body format
  216.     $indent = "";       # Goes in front of description to indicate treeness
  217.  
  218. # CHANGE--User-configurable defaults
  219.  
  220.     $breaklong = 15;    # CHANGE--Where to break long lists, place ". . ."
  221.     $= = 55;            # CHANGE--Lines per page
  222.     $iadd = "  ";       # CHANGE--Amount to indent each new level
  223.  
  224. # Real work
  225.  
  226.     &GetList($CurrentHost, $Port, $Path, $indent);
  227.     exit(0);
  228.  
  229. #
  230. # Formats
  231. #
  232.  
  233. format TOP =
  234.  
  235. MSU Gopher Road Map                      Host: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  236. $firsthost
  237. Last Update: @<<<<<<<                                               Page: @>>
  238. $today $%
  239.  
  240. Name                    Type    Destination
  241. --------------------------------------    -------    ------------------------------
  242. .
  243.  
  244. format STDOUT =
  245. @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  @<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  246. $fname $ftype $fhost
  247. .
  248. SHAR_EOF
  249. fi # end of overwriting check
  250. #    End of shell archive
  251. exit 0
  252.  
  253. ---------------------------------snip-------------------------------
  254. --
  255.  == Frustration is portable. ==
  256.