*** bin/spell.orig	Wed Mar 27 11:18:14 2002
--- bin/spell	Fri May  9 22:19:20 2003
***************
*** 13,16 ****
--- 13,17 ----
  
  ##MWB Debug
+ use strict;
  use lib ( '.' );
  use lib ( '../lib' );
***************
*** 22,36 ****
  #####################################
  #$path = '/usr/bin/aspell';
! $path = '/usr/bin/ispell';
  
  ######################################
  # SET GLOBAL VARIABLES
  ######################################
! @words=();		# global
! $wordframe="";	# global
! $wordcount=0;	# global
! $worderror=0;	# global
! $wordignore="";	# global
! $pageheaders = qq|
  <style>
  body	{
--- 23,37 ----
  #####################################
  #$path = '/usr/bin/aspell';
! our $path = '/usr/bin/ispell';
  
  ######################################
  # SET GLOBAL VARIABLES
  ######################################
! our @words=();		# global
! our $wordframe="";	# global
! our $wordcount=0;	# global
! our $worderror=0;	# global
! our $wordignore="";	# global
! our $pageheaders = qq|
  <style>
  body	{
***************
*** 99,111 ****
  #####################################
  sub _word2label {
! my $word=$_[0];
! my $label='%%WORD'.$wordcount.'%%';
! if ($wordignore=~/$word/i || $word =~/^WORD/) 
! 	{
! 	return($word);
! 	}
! $words[$wordcount]=$word;
! $wordcount++;
! return($label);
  }
  
--- 100,112 ----
  #####################################
  sub _word2label {
!    my $word=$_[0];
!    my $label='%%WORD'.$wordcount.'%%';
!    if ($wordignore=~/$word/i || $word =~/^WORD/) 
! 	   {
! 	   return($word);
! 	   }
!    $words[$wordcount]=$word;
!    $wordcount++;
!    return($label);
  }
  
***************
*** 117,130 ****
  
  # ignore valid contractions
! $wordignore  = "they'll we'll you'll she'll he'll i'll ";
! $wordignore .= "hasn't wouldn't shouldn't didn't aren't couldn't doesn't hadn't wasn't weren't isn't ";
! $wordignore .= "we've you've they've ";
  
! # ignore the following always
! $wordignore .= "http ftp nntp smtp nfs html xml mailto bsd linux gnu gpl openwebmail ";
  
! # open custom ignore
! if (-e 'custom.dic')
! 	{
  	local $/ = undef;
  	open(DICTIONARY, '<custom.dic');
--- 118,130 ----
  
  # ignore valid contractions
!    $wordignore  = "they'll we'll you'll she'll he'll i'll ";
!    $wordignore .= "hasn't wouldn't shouldn't didn't aren't couldn't doesn't hadn't wasn't weren't isn't ";
!    $wordignore .= "we've you've they've ";
  
!    # ignore the following always
!    $wordignore .= "http wiki twiki ftp nntp smtp nfs html xml mailto bsd linux gnu gpl openwebmail ";
  
!    # open custom ignore
!    if (-e 'custom.dic') {
  	local $/ = undef;
  	open(DICTIONARY, '<custom.dic');
***************
*** 135,150 ****
  
  # put url to ignore
! foreach ($text=~m![A-Za-z]+tp://[A-Za-z\d\.]+!ig) 
! 	{
  	$wordignore.=" $_";
  	}
  # put email to ignore
! foreach ($text=~m![A-Za-z\d]+\@[A-Za-z\d]+!ig) 
! 	{
  	$wordignore.=" $_";
  	}
  # put FQDN to ignore
! foreach ($text=~m![A-Za-z\d\.]+\.(com|org|edu|net|gov)[A-Za-z\d\.]*!ig)
! 	{
  	$wordignore.=" $_";
  	}
--- 135,147 ----
  
  # put url to ignore
! foreach ($text=~m![A-Za-z]+tp://[A-Za-z\d\.]+!ig) {
  	$wordignore.=" $_";
  	}
  # put email to ignore
! foreach ($text=~m![A-Za-z\d]+\@[A-Za-z\d]+!ig) {
  	$wordignore.=" $_";
  	}
  # put FQDN to ignore
! foreach ($text=~m![A-Za-z\d\.]+\.(com|org|edu|net|gov)[A-Za-z\d\.]*!ig) {
  	$wordignore.=" $_";
  	}
***************
*** 161,173 ****
  ###########################################
  sub query2words {
! my $q=$_[0];
! my $i;
! @words=();
! $wordcount=$q->param('wordcount');
! $wordframe=CGI::unescape($q->param('wordframe'));
! for ($i=0; $i<$wordcount; $i++)
! 	{
  	$words[$i]=$q->param($i) if (defined ($q->param($i)))
! 	}
  }
  
--- 158,169 ----
  ###########################################
  sub query2words {
!     my $q=$_[0];
!     my $i;
!     @words=();
!     $wordcount=$q->param('wordcount');
!     $wordframe=CGI::unescape($q->param('wordframe'));
!     for ($i=0; $i<$wordcount; $i++) {
  	$words[$i]=$q->param($i) if (defined ($q->param($i)))
!     }
  }
  
***************
*** 262,266 ****
  <body onLoad="self.focus();">
  <center>
! <form method="POST" action="/twiki/bin/spell.pl">
  <table border="0">
  <tr>
--- 258,262 ----
  <body onLoad="self.focus();">
  <center>
! <form method="POST" action="/twiki/bin/spell">
  <table border="0">
  <tr>
***************
*** 345,349 ****
  <tr>
  <td align="center">
! Click <a href="/twiki/bin/spell.pl">here</a> to check more text.
  <br>
  Click <a href="#" onclick="window.close();">here</a> to close this window.
--- 341,345 ----
  <tr>
  <td align="center">
! Click <a href="/twiki/bin/spell">here</a> to check more text.
  <br>
  Click <a href="#" onclick="window.close();">here</a> to close this window.
***************
*** 393,397 ****
  <tr>
  <td align="center">
! <form action="/twiki/bin/spell.pl" method="POST">
  <textarea rows="8" cols="50" name="checkme"></textarea>
  <br>
--- 389,393 ----
  <tr>
  <td align="center">
! <form action="/twiki/bin/spell" method="POST">
  <textarea rows="8" cols="50" name="checkme"></textarea>
  <br>
***************
*** 452,496 ****
  # MAIN LOOP!
  #####################################
! my $query = new CGI;
! my $string = $query->param('checkme');
! my $form = $query->param('form');
! my $field = $query->param('field');
! 
! untie *STDIN;
! 
! print "Content-type: text/html\n\n";
! if ($query->param('spell') eq 'check')
! 	{
! 	if ($ENV{HTTP_REFERER} !~ $ENV{HTTP_HOST})
! 		{
! 		&error;
! 		exit;
! 		}
! 	$pid = open3(\*WRITER,\*READER,\*ERROR,"$path -a -S") or die "Can't open aspell!";
! 	&TWiki::Func::writeDebug("my open3 PID = $pid");
!         text2words($string);
! 	checkit($form, $field);
! 	close READER;
! 	close WRITER;
! 	wait;
! 	} 
! elsif ($query->param('Finish Checking') eq 'Finish Checking')
! 	{
! 	query2words($query);
! 	final($form, $field);
! 	}
! elsif ($query->param('Check Again') eq 'Check Again')
! 	{
! 	$pid = open3(\*WRITER,\*READER,\*ERROR,"$path -a -S") or die "Can't open aspell!";
! 	query2words($query);
! 	checkit($form,$field);
! 	close READER;
! 	close WRITER;
! 	wait;
! 	} 
! else	{
! 	&asktext;
! 	}
! 
  exit;
  
--- 448,493 ----
  # MAIN LOOP!
  #####################################
! sub main {
!     my $query = new CGI;
!     my $string = $query->param('checkme');
!     my $form = $query->param('form');
!     my $field = $query->param('field');
!     my $pid ;
!     
!     untie *STDIN;
!     
!     print "Content-type: text/html\n\n";
!     if ($query->param('spell') eq 'check')
!     	{
!     	if ($ENV{HTTP_REFERER} !~ $ENV{HTTP_HOST}) {
!     		&error;
!     		exit;
!     		}
!     	my $pid = open3(\*WRITER,\*READER,\*ERROR,"$path -a -S") or die "Can't open aspell!";
!     	&TWiki::Func::writeDebug("my open3 PID = $pid");
!             text2words($string);
!     	checkit($form, $field);
!     	close READER;
!     	close WRITER;
!     	wait;
!     	} 
!     elsif ($query->param('Finish Checking') eq 'Finish Checking') {
!     	query2words($query);
!     	final($form, $field);
!     	}
!     elsif ($query->param('Check Again') eq 'Check Again') {
!     	$pid = open3(\*WRITER,\*READER,\*ERROR,"$path -a -S") or die "Can't open aspell!";
!     	query2words($query);
!     	checkit($form,$field);
!     	close READER;
!     	close WRITER;
!     	wait;
!     	} 
!     else	{
!     	&asktext;
!     	}
! }
! 	
! &main();
  exit;
  
