home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / perl / 7104 < prev    next >
Encoding:
Internet Message Format  |  1992-11-23  |  6.4 KB

  1. Path: sparky!uunet!nestroy.wu-wien.ac.at!dec4.wu-wien.ac.at!neumann
  2. From: neumann@dec4.wu-wien.ac.at (Gustaf Neumann)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: Is there a Perl/Wafe gopher client out there?
  5. Date: Mon, 23 Nov 92 15:59:07 MET
  6. Organization: WU-Wien
  7. Lines: 185
  8. Distribution: world
  9. Message-ID: <7225307468-311911@dec4.wu-wien.ac.at>
  10. References: <1992Nov23.122835.9289@meiko.com>
  11. NNTP-Posting-Host: dec4.wu-wien.ac.at
  12.  
  13. In article <1992Nov23.122835.9289@meiko.com> from [23 Nov 92 12:28:35 GMT] you wrote:
  14.  |> Has anyone implemented a Perl gopher (or gopher+) client, or better
  15.  |> still one in Perl which uses the Wafe front end?
  16.  |> 
  17. I would not call the following program an elaborate wafe gopher 
  18. front end, but you should be able to use it as a starting point.
  19. it handles the most basic gopher codes. Enhancements are welcome.
  20. The program below is a sightly improved version of the wafegopher
  21. program of the wafe distribution. You need wafe 0.92 or better.
  22.  
  23. -gustaf
  24. =========================================================
  25. #!/usr/local/bin/perl 
  26. #
  27. # Date: Mon, Aug 13 1992
  28. # Author: Gustaf Neumann
  29. # Version: 0.92
  30. #
  31. #      Wirtschaftsuniversitaet Wien,
  32. #      Abteilung fuer Wirtschaftsinformatik
  33. #      Augasse 2-6,
  34. #      A-1090 Vienna, Austria
  35. #      neumann@wu-wien.ac.at, nusser@wu-wien.ac.at
  36. #
  37. # Permission to use, copy, modify, and distribute this software and its
  38. # documentation for any purpose and without fee is hereby granted, provided
  39. # that the above copyright notice appears in all copies and that both that
  40. # copyright notice and this permission notice appear in all supporting
  41. # documentation.  This software is provided "as is" without expressed or
  42. # implied warranty.
  43.  
  44. %privOptions = (
  45.     "p", "gopher port: default is 70",
  46.     "s", "gopher server: default is gopher.micro.umn.edu",
  47.     );
  48.  
  49. $WafeLib = $ENV{'WAFELIB'} || "/usr/lib/X11/wafe";
  50. require "$WafeLib/perl/wafe.pl";
  51. require 'chat2.pl';
  52.  
  53. $opt_p = $opt_p || 70; # default gopher port
  54. $gopherServer = $opt_s || "gopher.micro.umn.edu";
  55.  
  56. @res = (
  57.     'leftBitmap $WafeBitmaps/text.xbm callback {echo r text $l1 $shp}', #0
  58.     'leftBitmap $WafeBitmaps/folder.xbm callback {echo r dir $l1 $shp}', #1
  59.     '', #2
  60.     '', #3
  61.     '', #4
  62.     '', #5
  63.     '', #6
  64.     'leftBitmap $WafeBitmaps/search.xbm callback {global l sel hp;'
  65.               .'set l {$l1};set sel {$sel};set hp {$hp};'
  66.           .'popup searchmenu none}', #7
  67.     'leftBitmap $WafeBitmaps/telnet.xbm callback {echo telnet $shp}', #8
  68.     );
  69.  
  70. sub listing {
  71.     local($query) = @_;
  72.     local($fail,$string,$conn);
  73.     local($q,$server,$port) = 
  74.     ($query =~ /^([^\t]*)\t([^\t]+)\t(\d+)\D?/) ?
  75.         ($1,$2,$3) : ();
  76.     ($server,$port) = ($1,$2) if !$server && $query =~ /^([^\t]+)\t(\d+)\D?/;
  77.  
  78.     &Xui("sV i$l0 label {retrieving data from $server...}") if $level;
  79.  
  80.     ($conn = &chat'open_port($server, $port)) || return ("cannot open connection","");
  81.     &chat'print($conn, "$q\r\n");
  82.  
  83.     $* = 1;
  84.     ($fail,$string) = &chat'expect($conn, 30, 
  85.            '^\.\r?\n', '("",$`)', 
  86.             'TIMEOUT','("timeout","")');
  87.     $* = 0;
  88.     $string =~ tr/\r//d;
  89.     return($fail,$string);
  90. }
  91.  
  92. $widget = "waaa";
  93. sub newWidget {
  94.     return $widget++;
  95. }
  96.  
  97. sub replyList {
  98.     local($t,$level,$query) = @_;
  99.     local($l0,$l1,$vert,$shell,$callback) = ($level-1,$level+1);
  100.     &Xui("sV i$level label {only one window for each level allowed}"), return 
  101.     if $blocked{$level};
  102.  
  103.     $blocked{$level} = 1;
  104.     local($fail,$string) = &listing($query);
  105.     &Xui("sV i$l0 label {$fail}") if $level;
  106.     undef $blocked{$level}, return 
  107.     if $fail;
  108.  
  109.     local($lines) = ($string =~ tr/\n/\n/);
  110.     &Xui("sV i$l0 label {no data available}"), 
  111.         undef $blocked{$level}, return 
  112.     if $lines == 0 && $level>0;
  113.  
  114.     if ($level) {
  115.         local($off)=$level*30;
  116.     &Xui("transientShell t$level f0;callback t$level popupCallback position f$l0:$off/$off");
  117.     $shell = "t$level";
  118.     } else {
  119.     $shell = "topLevel";
  120.     }
  121.  
  122.     &Xui("form ff$level $shell borderWidth 0 $backGround");
  123.  
  124.     if ($t eq "dir") {
  125.     local($height) = "height 300" if  $lines > 20;
  126.     &Xui("viewport v$level ff$level allowVert true $height borderWidth 0;"
  127.          ."form f$level v$level");
  128.     &Xui("sV i$l0 label {preparing display with $lines lines ...}") if $level; 
  129.     foreach((split(/\n/,$string))) { 
  130.         if (/^(\d)([^\t]+)\t(.*)$/) {
  131.         local($type,$label,$shp) = ($1,$2,$3);
  132.                 ($sel,$hp) = ($1,$2) if $shp =~ /^([^\t]*)\t(.*)$/;
  133.                 $shp =~ s/\t/\\t/g;
  134.         local($w) = &newWidget();
  135.         eval '$callback = "'.@res[$type].'"';
  136.         &Xui("command $w f$level label {$label} $vert width 500 borderWidth 0 "
  137.              ."justify left $callback");
  138.         $vert = "fromVert $w";
  139.         }
  140.     }
  141.     $vert = "fromVert v$level";
  142.     &Xui("sV i$l0 label {}") if $level;
  143.     } else {
  144.     local($w) = &newWidget();
  145.         local($height) = "height 300" if $lines > 1;
  146.     &Xui("asciiText $w ff$level width 500 $height scrollVertical always "
  147.             ."$roColors $textFont type string");
  148.     &wafe'tunnel("COMM",$string,"sV $w string \$COMM");
  149.         &wafe'applyActions($w,@textActions);
  150.     $vert = "fromVert $w";
  151.     }
  152.     $callback = $level ? 
  153.         "callback {echo free $level;destroyWidget t$level}" : "callback quit";
  154.     &Xui("command q$level ff$level label Quit $buttonAtts $vert $callback;"
  155.         ."label i$level ff$level label {} width 470 $infoColors $vert fromHoriz q$level");
  156.     &Xui("popup t$level none") if $level;
  157. }
  158.  
  159. &UI( <<"End of TCL");
  160.    transientShell searchmenu topLevel 
  161.    callback searchmenu popupCallback positionCursor 45
  162.  
  163.    dialog searchtext searchmenu label {Search string:} value {} $backGround
  164.    sV searchtext.label $backGround $boldFont
  165.    command searchquit searchtext label {cancel} $buttonAtts \\
  166.           callback {popdown searchmenu}
  167.  
  168.    action searchtext.value  override \\
  169.        {<Key>Return: exec(global l; global sel; global hp; \\
  170.        echo r dir \$l \$sel\\t\[gV searchtext value\]\\t\$hp) \\
  171.        XtMenuPopdown(searchmenu) }
  172.  
  173. set sel ""
  174. set l 1
  175. set hp ""
  176. End of TCL
  177.  
  178. &replyList("dir",0,"\t$gopherServer\t$opt_p");
  179. &Xui("realize");
  180.  
  181. while(<STDIN>) {
  182.     &replyList($1,$2,$3) if /^r\s+(\S+)\s+(\S+)\s+(.*)$/;
  183.     if (/^telnet\s*(\S*)\t(\S+)\t(.*)$/) {
  184.         local($port) = $3 if $3>0;
  185.         local($title) = "-T 'login $1'" if $1 ne "";
  186.         system("xterm $title -e telnet $2 $port&");
  187.     }
  188.     undef $blocked{$1} if /^free (\d+)/;
  189. }
  190. &wafe'cleanup();
  191.  
  192. --
  193. Gustaf Neumann          neumann@dec4.wu-wien.ac.at, neumann@awiwuw11.bitnet
  194. Vienna University of Economics and Business Administration 
  195. Augasse 2-6,  A-1090 Vienna, Austria        
  196. Tel: +43 (222) 31-336 x4533      Fax: 347-555
  197.  
  198.