home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / perl / scripts-convex / vspell < prev    next >
Encoding:
Text File  |  1991-03-11  |  1.1 KB  |  49 lines

  1. #!/usr/local/bin/perl
  2.  
  3. $strategy = 'standout';
  4. $USAGE = "usage: $0 [-f localdict] files ...\n";
  5.  
  6. if ($ARGV[0] eq '-f') {
  7.     shift;
  8.     $WORDS = shift || die $USAGE;
  9.     &read_dict;
  10. } elsif (-r ($WORDS = $ENV{'HOME'} . '/.ispell_words')) {
  11.     &read_dict;
  12.  
  13. sub read_dict {
  14.     open WORDS || die "can't open $WORDS $!";
  15.     while (<WORDS>) {
  16.     chop; $seen{$_}++;
  17.     } 
  18.  
  19. die $USAGE unless @ARGV;
  20.  
  21. $code = "while (<>) {\n    study;\n";
  22. if ($strategy ne 'underline') {
  23.     # ($SO, $SE) = ('*[ ',  ' ]*');  # like diction
  24.     ($SO, $SE) = ("\033[7m",  "\033[m"); # vt100 standout
  25. }
  26. open(SPELL, "spell @ARGV |");
  27. while (<SPELL>) {
  28.     chop;
  29.     next if $seen{$_};
  30.     ($lhs = $_) =~ s/(\W+)/\\$1/g;
  31.     if ($strategy eq 'underline') {
  32.     s/(.)/$1\b$1/g;
  33.     $code .= "    s/\\b$lhs\\b/$_/g;\n";
  34.     } else {
  35.     $code .= "    s/\\b$lhs\\b/$SO$_$SE/g;\n";
  36.     }
  37. close(SPELL) || die "can't spell @ARGV";
  38. $code .= "    print;\n}\n";
  39. #print STDERR $code;
  40. open (PAGER, "| ". ($PAGER = $ENV{'PAGER'} || 'more') . " -f");
  41. select(PAGER);
  42. eval $code;
  43. die $@ if $@;
  44. close(PAGER);
  45. die "$PAGER pipe failed" if $?;
  46.