yukngo@obelix.gaul.csd.uwo.ca (Cheung Yukngo) (05/31/90)
Well, this is the first semi-serious perl program I wrote two months ago (I started using rcs about three weeks ago). I did not test it very extensively. Send me bugs/suggestions/diffs/comments. Tell me if you like it; tell me if you don't. Please send to clipper@csd.uwo.ca as I use this machine (obelix) only for reading news. Thanks. Khun Yee clipper@csd.uwo.ca #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # pwebs # if test -f 'pwebs' then echo shar: will not over-write existing file "'pwebs'" else echo x - 'pwebs' sed 's/^X//' >'pwebs' << 'SHAR_EOF' X#!/u3/thesis/clipper/pl/perl X# A simple webster client in perl X# Copyright (c) 1990 Khun Yee Fung (clipper@csd.uwo.ca) X# No warranty. See the end of this program for details. X# $Id: pwebs,v 1.2 90/05/10 16:28:46 clipper Exp $ X# $Source: /u3/thesis/clipper/pl/RCS/pwebs,v $ X Xdo 'sys/socket.h' || die "can\'t do sys/socket.h: $@"; Xdo 'getopts.pl' || die "can\'t do getopts.pl: $@"; Xdo Getopts(':fstmcuv'); X$version = "1.0"; X X@prog = split("/", $0); Xif (defined($opt_u) || $#ARGV < $[) { X print "Usage: $prog[$#prog] [-f] [-t] [-m] [-c] [-u] [-v] [words] X -f search for the word in the full dictionary X -t check the word in the thesaurus instead of the dictionary X -m check the words with the prefix given X -c check if the word is a complete word X -u print this message X -v print the version of this program X default is to check the definition of the words\n"; X exit 0; X} Xelsif (defined($opt_v)) { X print "$prog[$#prog], version $version\n"; X exit 0; X} X X$sockaddr = 'S n a4 x8'; # Magic words! X$hostname = "icarus"; # our webster host. X$port = 2627; X(($name, $aliases, $type, $len, $saddr) = gethostbyname($hostname)) X || die "no websterhost \"$hostname\"\n"; X$sin = pack($sockaddr, 2, $port, $saddr); X X$SIG{'INT'} = 'IGNORE'; Xsocket(SERVER, 2, 1, 0) || die "socket: $!"; Xconnect(SERVER, $sin) || die "connect: $!"; X$SIG{'INT'} = 'dokill'; X Xselect(SERVER); $| = 1; select(STDOUT); $| = 1; X$key = "DEFINE"; Xoption: { X defined($opt_t) && ((printf SERVER "INDEX thesaurus\n"), last option); X defined($opt_f) && ((printf SERVER "INDEX dictionary-full\n"), last option); X defined($opt_s) && ($key = "SPELL", last option); X defined($opt_m) && ($key = "ENDINGS", last option); X defined($opt_c) && ($key = "COMPLETE", last option); X} X Xwhile ($word = shift) { X print "\n\n---> ", $word, "\n"; X printf SERVER "%s %s\n", $key, $word; X X $_ = <SERVER>; X response: { X /WILD 0/ && ((print "No match\n"), last response); X /WILD/ && ((print "Matches are:\n"), do listlines(), last response); X /SPELLING 0/ && ((print "Can\'t find this word\n"), last response); X /SPELLING 1/ && ((print "Correct Spelling\n"), last response); X /SPELLING/ && ((print "Maybe you mean:\n"), do listlines(), last response); X /DEFINITION ([\d]+)/ && (do listlines(), last response); X /ERROR FATAL/ && ((print "Fatal Error:", $'), last response); X /ERROR/ && ((print "Error: ", $'), last response); X /AMBIGUOUS ([\d]+)/ && ((print "$1 possible matches\n"), last response); X /COMPLETION (.+)/ && ((print $1, "\n"), last response); X /MATCHS 0/ && ((print "Matches nothing\n"), last response); X /MATCHS/ && ((print "Matches:\n"), do listlines(), last response); X print "$_\n"; X } X} Xclose SERVER; X X X# SUBROUTINES Xsub listlines{ X $/ = "\200"; X $buf = <SERVER>; X $buf =~ s/[\r\200]//g; X print $buf; X $/ = "\n"; X} X X# kill the connection Xsub dokill { close SERVER; exit 1; } X X# Copyright 1990 Khun Yee Fung <clipper@csd.uwo.ca> X# X# Permission to use, copy, modify, and distribute, this software and its X# documentation for any purpose is hereby granted without fee, provided that X# the above copyright notice appear in all copies and that both that X# copyright notice and this permission notice appear in supporting X# documentation, and that the name of the copyright holders be used in X# advertising or publicity pertaining to distribution of the software with X# specific, written prior permission, and that no fee is charged for further X# distribution of this software, or any modifications thereof. The copyright X# holder make no representations about the suitability of this software for X# any purpose. It is provided "as is" without express or implied warranty. X# X# THE COPYRIGHT HOLDER DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, X# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO X# EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR X# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, X# DATA, PROFITS, QPA OR GPA, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE X# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR X# PERFORMANCE OF THIS SOFTWARE. SHAR_EOF if test 4193 -ne "`wc -c < 'pwebs'`" then echo shar: error transmitting "'pwebs'" '(should have been 4193 characters)' fi fi echo Done exit 0