#!/usr/bin/perl -w # # Terjes WWWebster client version 2.19 4/2-2007 # Copyright ©1997 ©2007 Terje Bråten E-mail: terjebr@broadpark.no # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even any implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # This program assumes your terminal can handle the ISO-8859-1 char-set. use strict; use Socket; my ($VERSION) = '2.19'; my $gotReadKey = 0; if (!defined $ENV{'WEBSTER_NOAUTOWRAP'}) { eval {require Term::ReadKey; import Term::ReadKey;}; if ($@ eq "") { # we have ReadKey, $gotReadKey = 1; } } =head1 NAME webster - look up English words in the Webster dictionary =head1 SYNOPSIS B [B<-l>] [B<-i> | B<-I>] [B<-d> I | B<-t> I | B<-v> | B<-c> | B<-?> | B<-m> | I] I is a word to find in the dictionary. =head1 DESCRIPTION A tiny WWW-browser that connects to the WWWebster dictionary at B and provides an convenient access to the dictionary from the command line. It is based on Merriam-Webster's Collegiate® Dictionary, 10th Edition published by Merriam-Webster Inc. =head1 OPTIONS =over 10 =item B<-l> Long format (same as setting the environment variable B=1) =item B<-i> Do not convert italic words to all uppercase words. =item B<-I> Do convert all italic words to all uppercase words. (This is the default, unless the environment variable B is true.) =item B<-d> I Use the dictionary to define I. This is the same as to just specify a I with no options, except that I can begin with a hypen without being parsed as an option. =item B<-t> I Use the thesaurus to find a I instead of using the dictionary. =item B<-v> Display version info. =item B<-c> Display the credit. =item B<-?> or B<-h> Display usage help. =item B<-m> Read your mail =back =head1 USAGE In its most common use, B connects to the WWWebster dictionary, fetches the definition of the requested word, prints that definition to standard output and exits successfully. If there are multiple words matching the requested word, B prints a numbered list of possible words and lets you choose which word you want a definition for. Likewise, if the requested word does not exist, B gives a list of similar words to choose from. In this way, the program can be used as a spelling checker. =head1 ENVIRONMENT If you have set the environment variable B to true (or anything nonzero) this WWWebster client will insert more newlines in the output. To stop the program from converting all italic words to all uppercase words you can set B to true (or anything nonzero). If B is not set then the lines will wrap so the text only uses 90% of your terminal width, provided the C module is available in your perl interpreter. For those that do not (want to) have the module C I have also included support for the enironment variable B. If B is set to a non-zero value it is taken as a fixed linewith to wrap the text at. If your terminal is 80 characters wide, a good value for B can be 72. B is ignored if the module C is found and B is not set. =head1 PREREQUISITES This perl script requires the C module that enables you to open a socket to a tcp/ip internet connection. The terminal running the script must be able to handle the full 8-bits ISO-8859-1 char-set. =head1 COREQUISITES This script wants to use the C module to determine the width of your terminal, but it can do without it. =head1 CREDIT This client for the WWWebster dictionary would not be possible if Merriam-Webster Inc had not put their dictionary on the web for everyone to use. The WWWebster dictionary is found at B Based on Merriam-Webster's Collegiate® Dictionary, 10th Edition published by Merriam-Webster Inc. =head1 AUTHOR Written by Terje Bråten . =head1 README A tiny WWW-browser that connects to the WWWebster dictionary at http://www.m-w.com/ and provides an convenient access to the dictionary from the command line. =pod OSNAMES any =pod SCRIPT CATEGORIES Web =cut my ($more_linebreaks) = 0; # Set $more_linebreaks to be non-zero if you want to put # more line breaks (newlines) into the output. my ($upper_italic) = 1; # Set $upper_italic to be non-zero if you want to convert # italic words to upper case words in the output. if ($ENV{'WEBSTER_VERBOSE'}) { $more_linebreaks = 1; } if ($ENV{'WEBSTER_NOUPPERITALIC'}) { $upper_italic = 0; } my $Wchar = 0; if ($gotReadKey) { #added by jcox #Term::Size seems broken on NT, therefore I'm using Term::ReadKey ($Wchar) = GetTerminalSize(); $Wchar = int(.90 * $Wchar); } elsif ($ENV{'WEBSTER_FIXEDWRAP'}) { $Wchar = int($ENV{'WEBSTER_FIXEDWRAP'}); } my ($word) = shift; my ($option) = ""; my ($Book) = "Dictionary"; my ($optDone) = 0; die "No word to define. (Use option -h for help.)\n" unless $word; if ($word =~ s/^-+//) { $option = $word; $word = shift; } if ($option =~ m/^l/i) { $more_linebreaks = 1; $optDone = 1; } if ($optDone) { if (defined $word && $word =~ s/^-+//) { $option = $word; $word = shift; } $optDone = 0; } if ($option =~ m/^i/) { $upper_italic = 0; $optDone = 1; } if ($option =~ m/^I/) { $upper_italic = 1; $optDone = 1; } if ($optDone) { if (defined $word && $word =~ s/^-+//) { $option = $word; $word = shift; } } if ($option =~ m/^c/i) { print " This client for the WWWebster dictionary would not be possible if Merriam-Webster Inc had not put their dictionary on the web for everyone to use. The WWWebster dictionary is found at http://www.m-w.com/ Based on Merriam-Webster's Collegiate® Dictionary, 10th Edition published by Merriam-Webster Inc. "; exit; } if ($option =~ m/^v/i) { print "Terjes webster agent, version $VERSION\n"; exit; } if ($option =~ m/\?|^h/i) { my ($prog) = $0; $prog =~ s:^.*/::; print " Terjes webster agent, version $VERSION. This is a tiny WWW-browser that connect to the WWWebster dictionary at http://www.m-w.com/ It is based on Merriam-Webster's Collegiate® Dictionary, 10th Edition published by Merriam-Webster Inc. Syntax: $prog