home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / alt / gopher / 1074 < prev    next >
Encoding:
Text File  |  1992-07-25  |  5.0 KB  |  193 lines

  1. Newsgroups: alt.gopher
  2. Path: sparky!uunet!stanford.edu!leland.Stanford.EDU!schemers
  3. From: schemers@leland.Stanford.EDU (Roland Schemers)
  4. Subject: gopher<->Webster perl script
  5. Message-ID: <1992Jul25.001230.21597@leland.Stanford.EDU>
  6. Sender: news@leland.Stanford.EDU (Mr News)
  7. Organization: Distributed Computing Group, Stanford University
  8. Date: Sat, 25 Jul 92 00:12:30 GMT
  9. Lines: 182
  10.  
  11. Ok, here is yet another gopher gateway. Gopher to webster (dictionary
  12. server). You need a webster server to point your links at, and a machine
  13. to run the gopher<->webster daemon.
  14.  
  15. You have to run it from inetd.
  16.  
  17. ----------------------------------------------------------------------
  18. This gopher to webster gateway works by defining a simple command
  19. format which takes Index queries sent by gopher clients.
  20.  
  21. When a gopher client sends back the selector string plus the input, the
  22. gopher2webster daemon will send the query to the webster daemon. If there 
  23. are no matches then a '.' is returned. If there are matches, they
  24. are returned as files and the selector will contain the correct string
  25. which will return the definition if the user selects it.
  26.  
  27. The gopher2webster daemon should be run from inetd. You need to pick
  28. a port to run it on and set that port in the config file. Stanford's
  29. webster server wont answer queries off our net, so you need to 
  30. use another webster that will. You can look at the Webster menu at
  31. Stanford's experiMENTAL root gopher server:
  32.  
  33.   gopher-server.stanford.edu 70
  34.  
  35. But at some point access will probably be restricted to SUNet.
  36.  
  37. The gopher2webster gateway uses the following format for commands:
  38.  
  39. index command word
  40.  
  41. Where:
  42.  
  43. index   Tells the webster server which index to look at.
  44.  
  45.          NeXT webster servers let you specifiy:
  46.  
  47.          dictionary      the default
  48.          thesaurus       the Webster's Thesaurus
  49.          dictionary-full the full content dictionary index            
  50.  
  51.          If your webster server doesn't understand the "INDEX" 
  52.          command use default.
  53.  
  54. command  Is a webster command, like:
  55.  
  56.            DEFINE
  57.            SPELL
  58.            ENDINGS
  59.  
  60. word     Is the word you are looking up.
  61.  
  62.  
  63. Examples:
  64.  
  65. default SPELL webster
  66. default DEFINE spell
  67. default ENDINGS foo
  68.  
  69. thesaurus SPELL hot
  70. thesaurus DEFINE hot
  71.  
  72. How it works with gopher:
  73.  
  74. Set up the following Links. The port 'nnn' and host HOSTNAME should point 
  75. to where your gopher2webster gateway is running.
  76.  
  77. Name=Lookup word in dictionary
  78. Type=7
  79. Port=nnn
  80. Path=default SPELL
  81. Host=HOSTNAME
  82.  
  83. Name=Show words that start with
  84. Type=7
  85. Port=nnn
  86. Path=default ENDINGS
  87. Host=HOSTNAME
  88.  
  89. If your webster server does understand the "INDEX" command, you can also add:
  90.  
  91. Name=Search text of entire dictionary
  92. Type=7
  93. Port=nnn
  94. Path=dictionary-full SPELL
  95. Host=HOSTNAME
  96.  
  97. Name=Thesaurus
  98. Type=7
  99. Port=nnn
  100. Path=thesaurus SPELL
  101. Host=HOSTNAME
  102.  
  103.  
  104. #!/usr/local/bin/perl
  105. #
  106. # switch to nobody
  107. #
  108.  
  109. ($<,$>) = (-2,-2) unless $>;
  110.  
  111. # select your webster server and local port
  112. #
  113.  
  114. $webster_server  = "webster.lcs.mit.edu";
  115. $webster_port    = 103;
  116.  
  117. # stanford NeXT webster server
  118. #
  119. # $webster_server = "webster-server.stanford.edu";
  120. # $webster_port   = 765;
  121.  
  122. $port=&my_port;               # port this script is running on 
  123.  chop($host = `hostname`);
  124.  
  125.  $_ = <STDIN>; s/\r//; s/\n//;
  126.  
  127.  ($index,$cmd,$query) = /(\S+)\s+(\S+)\s+(\S+)/;
  128.  
  129.   &open_webster($webster_server,$webster_port);
  130.  
  131.   print WEBSTER "INDEX $index\r\n" if ($index ne 'default');
  132.  
  133.   if ($cmd eq "PSPELL") {                     # phonetic lookup
  134.        print WEBSTER "SPELL $query ?\r\n";
  135.   } else {
  136.        print WEBSTER "$cmd $query\r\n";
  137.   }
  138.  
  139.   $_ = <WEBSTER>; chop; chop;
  140.  
  141.   if (/^SPELLING 0/ || /^WILD 0/) {
  142.         &reply(".");
  143.    } elsif (/^SPELLING 1/) {
  144.       &reply("0$query\t$index DEFINE $query\t$host\t$port"); 
  145.       &reply(".");
  146.    } elsif (/^SPELLING$/ || /^MATCHS$/ || /^WILD/) {
  147.         $/ = "\200";
  148.         $buf = <WEBSTER>;
  149.         $buf =~ s/[\r\200]//g;
  150.         foreach (split(/\n/,$buf)) { /\d+\s+(\S+)/; $words{$1}=""; }
  151.         foreach (sort keys %words) { 
  152.                &reply("0$_\t$index DEFINE $_\t$host\t$port"); 
  153.         }
  154.         &reply(".");
  155.    } elsif (/^DEFINITION/) {
  156.         $/ = "\200";
  157.         $buf = <WEBSTER>;
  158.         $buf =~ s/[\r\200]//g;
  159.         print $buf;
  160.    }
  161.  
  162.   print WEBSTER "QUIT\r\n";
  163.   close(WEBSTER);
  164.  
  165. sub open_webster {
  166.  local($server,$port) = @_;
  167.  $sockaddr = 'S n a4 x8';
  168.  (($name, $aliases, $type, $len, $saddr) = gethostbyname($server))||&death;
  169.  $sin = pack($sockaddr, 2, $port, $saddr);
  170.  socket(WEBSTER, 2, 1, 0) || &death;
  171.  connect(WEBSTER, $sin)   || &death;
  172.  select(WEBSTER); $| = 1; select(STDOUT); $| = 1;
  173.  
  174. }
  175.  
  176. sub reply { print "$_[0]\r\n";}
  177. sub death { &reply("."); exit; }
  178.  
  179. sub my_port {
  180.    return -1 if (-t STDIN);
  181.    $sockaddr = 'S n a4 x8';
  182.    $mysockaddr = getsockname(STDIN);
  183.    ($myfamily,$myport,$myaddr) = unpack($sockaddr,$mysockaddr);
  184.    return $myport;
  185. }
  186.  
  187.  
  188. -- 
  189. Roland J. Schemers III              |            Networking Systems
  190. Systems Programmer                  |            168 Pine Hall   (415)-723-6740
  191. Distributed Computing Group         |            Stanford, CA 94305-4122
  192. Stanford University                 |            schemers@Slapshot.Stanford.EDU
  193.