[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

l10n-check 0.2.5



Bonjour,

Suite à la relecture du fichier po de Martin, voici quelques
modifications.

Journal :
version 0.2.5
  - add: facilty to accept a word for session or to put it in personal
    dictionary when spelling
  - add: personalize comment in review mode when providing manual correction
  - change: update doc for better presentation
  - bug fix:
    - add: define empty `$choice' when replacing with an empty string
    
il faut ajouter une ligne dans votre .l10n-check :
$spell_all	= "no";

Si vous mettez la valeur à « yes », le script s'arrêtera sur tous mots
inconnus par ispell lors de la correction orthographique, sinon, il ne
s'arrêtera que s'il peut proposer des corrections.

Nouvelles possibilités :
lors de la correction orthographique, vous pouvez entrer à l'invite :
- « A », pour accepter le mot pour la session en cours ;
- « I », pour insérer le mot tel quel dans votre dico. perso. ;
- « U », pour ajouter le mot en bas de casse dans votre dico. perso. ;

Lorsque vous tapez <espace>, pour faire une correction manuelle, il vous
demande ensuite un commentaire si vous êtes en mode relecture.

La rustine est jointe, le script complet est toujours ici :
http://perso.wanadoo.fr/nico.berto/l10n-check/l10n-check.txt

le tarball :
http://perso.wanadoo.fr/nico.berto/l10n-check/l10n-check.tar.gz

J'ai aussi attaché un tarball contenant les fichiers de règles modifiés
(tous sauf « text »).

Je remercie Martin pour ses encouragement...
Mais c'est moins rigolo de relire s'il n'y a plus de fautes :))


Nicolas
-- 
--- l10n-check_0.2.4.txt	Sat Jan 26 14:14:49 2002
+++ l10n-check_0.2.5.txt	Thu Jan 31 19:49:12 2002
@@ -54,6 +54,7 @@
     $dictionary,		# = "francais";
     $word_letters,		# = "a-zÂâÀàÉéÊêÈèËëÎîÏïÔôÛûÙùÜüÇç'-";
     $review,			# = "no";
+    $spell_all,			# = "no";
     $highlight_text_color,	# = $TEXT_COLORS{'normal'}.$TEXT_COLORS{'red_h'};
     $comment_text_color,	# = $TEXT_COLORS{'normal'}.$TEXT_COLORS{'cyan'};
     $letter_color,		# = $TEXT_COLORS{'normal'}.$TEXT_COLORS{'green'};
@@ -62,13 +63,13 @@
 # Read the config file
 my $config = $ENV{HOME}."/.l10n-check";	# config file
 die("You must define \$rules_dir, \$rules_e, \$bak_e, \$comment, \$debug, \$ispell,\n"
-   ."\$dictionary, \$word_letters, \$review, \$highlight_text_color, \$comment_text_color,\n"
-   ."\$letter_color Perl variables in \$HOME/.l10n-check\n") unless -r $config;
+   ."\$dictionary, \$word_letters, \$review, \$spell_all, \$highlight_text_color,\n"
+   ."\$comment_text_color, \$letter_color Perl variables in \$HOME/.l10n-check\n") unless -r $config;
 scalar eval `cat $config`;	# get the variables
 
 # Test if variables are defined
 foreach (qw(rules_dir rules_e bak_e comment debug ispell dictionary word_letters review 
-	    highlight_text_color comment_text_color letter_color)) {
+	    spell_all highlight_text_color comment_text_color letter_color)) {
 	eval "\$config=\$$_";
 	suicide("\$$_ not defined in \$HOME/.l10n-check") unless ($config ne "");
 }
@@ -76,6 +77,7 @@
 my $normal_text_color    = $TEXT_COLORS{'normal'};
 my $Rules = {};
 my $Comments = {};
+my @Spelling;
 my $NC =     $normal_text_color;		# normal      text color
 my $CC = $NC.$comment_text_color;		# comment     text color
 my $HC = $NC.$highlight_text_color;		# highlighted text color
@@ -101,9 +103,9 @@
 
 =head1 SYNOPSIS
 
-l10n-check [-q] [--quiet] [-v] [--verbose n]
-           [-i] [--spell] [--dict] [-n] [--nospell]
-	   [-r] [--review] [-t] [--trans] filename"
+l10n-check [-q] [--quiet] [-v] [--verbose n] [-i] [--spell] [--dict] [-n]
+[--nospell] [-r] [--review] [-t] [--trans] [-a] [--all-words] [-k]
+[--known-words] filename
 
 =head1 DESCRIPTION
 
@@ -122,17 +124,41 @@
 asked for a string to replace the highlighted text. The script will replace the
 hightlighted text with your choice and parse it again for new errors.
 
+When checking spelling, you have three more choices:
+
+=over 4
+
+=item I<A>
+
+accept word for the whole session,
+
+=item I<I>
+
+insert word, capitalized as is, in your personal dictionary
+
+=item I<U>
+
+insert word, in lower case, in your personal dictionary
+
+=back
+
 =head1 OPTIONS
 
 Verbosity level:
 
 =over 4
 
-=item I<-q> I<--quiet>, quiet mode
+=item I<-q> I<--quiet>
+
+quiet mode
+
+=item I<-v>
 
-=item I<-v>, verbose, start at level 1, add more for more verbosity
+verbose, start at level 1, add more for more verbosity
 
-=item I<--verbose n>, set verbosity level to I<n>
+=item I<--verbose n>
+
+set verbosity level to I<n>
 
 =back
 
@@ -140,11 +166,25 @@
 
 =over 4
 
-=item I<-i> I<--spell>, check spelling with ispell
+=item I<-i> I<--spell>
+
+check spelling with ispell
+
+=item I<--dict language>
+
+use I<language> dictionary for ispell
+
+=item I<-n> I<--nospell>
+
+don't check spelling
+
+=item I<-a> I<--all-words>
 
-=item I<--dict language>, use I<language> dictionary for ispell
+stop on all words when spelling
 
-=item I<-n> I<--nospell>, don't check spelling
+=item I<-k> I<--known-words>
+
+stop on words only if there are proposals when spelling
 
 =back
 
@@ -152,9 +192,13 @@
 
 =over 4
 
-=item I<-r> I<--review>, review mode, add comments on lines beginning with `I<E<gt>E<gt> >'
+=item I<-r> I<--review>
+
+review mode, add comments on lines beginning with `I<E<gt>E<gt> >'
+
+=item I<-t> I<--trans>
 
-=item I<-t> I<--trans>, translator mode, don't add comments
+translator mode, don't add comments
 
 =back
 
@@ -176,29 +220,59 @@
 
 =over 4
 
-=item I<$rules_dir>, directory for rules description files [$ENV{HOME}/l10n-check]
+=item I<$rules_dir>
+
+directory for rules description files [$ENV{HOME}/l10n-check]
+
+=item I<$rules_e>
+
+extension for rules description files [rules]
+
+=item I<$bak_e>
+
+extension for backup files [bak]
+
+=item I<$comment>
+
+comment string for review [>> ]
 
-=item I<$rules_e>, extension for rules description files [rules]
+=item I<$debug>
 
-=item I<$bak_e>, extension for backup files [bak]
+verbosity level [0]
 
-=item I<$comment>, comment string for review [>> ]
+=item I<$ispell>
 
-=item I<$debug>, verbosity level [0]
+use ispell for spelling [yes]
 
-=item I<$ispell>, use ispell for spelling [yes]
+=item I<$dictionary>
 
-=item I<$dictionary>, dictionary to use with ispell
+dictionary to use with ispell
 
-=item I<$word_letters>, regural expression to define letters allowed to write a word [a-z-]
+=item I<$word_letters>
 
-=item I<$review>, set to `B<yes>' if you want review comments to be added in the output file
+regural expression to define letters allowed to write a word [a-z-]
 
-=item I<$highlight_text_color>, color used to highlight text, this should highlight space charactaters (see below for available colors) [$TEXT_COLORS{'red_h'}]
+=item I<$review>
 
-=item I<$comment_text_color>, color used for comments and hints [$TEXT_COLORS{'cyan'}]
+set to `B<yes>' if you want review comments to be added in the output file
 
-=item I<$letter_color>, color used for letters in choose menu [$TEXT_COLORS{'green'}]
+=item I<$spell_all>
+
+set to `B<yes>' if you want to stop on all unknown words when spelling,
+otherwise it stops only if there are alternatives [no]
+
+=item I<$highlight_text_color>
+
+color used to highlight text, this should highlight space charactaters (see
+below for available colors) [$TEXT_COLORS{'red_h'}]
+
+=item I<$comment_text_color>
+
+color used for comments and hints [$TEXT_COLORS{'cyan'}]
+
+=item I<$letter_color>
+
+color used for letters in choose menu [$TEXT_COLORS{'green'}]
 
 =back
 
@@ -206,47 +280,89 @@
 
 =over 4
 
-=item I<$TEXT_COLORS{'black'}>, black
+=item I<$TEXT_COLORS{'black'}>
+
+black
+
+=item I<$TEXT_COLORS{'red'}>
 
-=item I<$TEXT_COLORS{'red'}>, red
+red
 
-=item I<$TEXT_COLORS{'green'}>, green
+=item I<$TEXT_COLORS{'green'}>
 
-=item I<$TEXT_COLORS{'yellow'}>, yellow
+green
 
-=item I<$TEXT_COLORS{'blue'}>, blue
+=item I<$TEXT_COLORS{'yellow'}>
 
-=item I<$TEXT_COLORS{'magenta'}>, magenta
+yellow
 
-=item I<$TEXT_COLORS{'cyan'}>, cyan
+=item I<$TEXT_COLORS{'blue'}>
 
-=item I<$TEXT_COLORS{'white'}>, white
+blue
 
-=item I<$TEXT_COLORS{'black_h'}>, black background
+=item I<$TEXT_COLORS{'magenta'}>
 
-=item I<$TEXT_COLORS{'red_h'}>, red background
+magenta
 
-=item I<$TEXT_COLORS{'green_h'}>, green background
+=item I<$TEXT_COLORS{'cyan'}>
 
-=item I<$TEXT_COLORS{'yellow_h'}>, yellow background
+cyan
 
-=item I<$TEXT_COLORS{'blue_h'}>, blue background
+=item I<$TEXT_COLORS{'white'}>
 
-=item I<$TEXT_COLORS{'magenta_h'}>, magenta background
+white
 
-=item I<$TEXT_COLORS{'cyan_h'}>, cyan background
+=item I<$TEXT_COLORS{'black_h'}>
 
-=item I<$TEXT_COLORS{'white_h'}>, white background
+black background
 
-=item I<$TEXT_COLORS{'bold'}>, blod
+=item I<$TEXT_COLORS{'red_h'}>
 
-=item I<$TEXT_COLORS{'blink'}>, blink
+red background
 
-=item I<$TEXT_COLORS{'inverse'}>, video inverted
+=item I<$TEXT_COLORS{'green_h'}>
 
-=item I<$TEXT_COLORS{'normal'}>, normal
+green background
 
-=item I<$TEXT_COLORS{'underscore'}>, underlined
+=item I<$TEXT_COLORS{'yellow_h'}>
+
+yellow background
+
+=item I<$TEXT_COLORS{'blue_h'}>
+
+blue background
+
+=item I<$TEXT_COLORS{'magenta_h'}>
+
+magenta background
+
+=item I<$TEXT_COLORS{'cyan_h'}>
+
+cyan background
+
+=item I<$TEXT_COLORS{'white_h'}>
+
+white background
+
+=item I<$TEXT_COLORS{'bold'}>
+
+bold
+
+=item I<$TEXT_COLORS{'blink'}>
+
+blink
+
+=item I<$TEXT_COLORS{'inverse'}>
+
+video inverted
+
+=item I<$TEXT_COLORS{'normal'}>
+
+normal
+
+=item I<$TEXT_COLORS{'underscore'}>
+
+underlined
 
 =back
 
@@ -255,7 +371,7 @@
 This is a text file containing the rules for skipping comments and for syntax
 checking. Fields are defined on their own lines like this:
 
-I<name> [I<index>] = "I<value>"
+I<name> I<index> = "I<value>"
 
 =over 4
 
@@ -263,7 +379,8 @@
 
 =item I<value> can contain any type of characters
 
-=item Comments are no allowed on field lines but can be added anywhere else on lines starting with `#'.
+=item Comments are no allowed on field lines but can be added anywhere else on
+lines starting with `#'.
 
 =back
 
@@ -360,7 +477,7 @@
 
 =cut
 
-my $version = "0.2.4";
+my $version = "0.2.5";
 
 # Test if configuration as been made
 my @dir=split("/", $rules_dir);		# get all subdirs
@@ -494,19 +611,21 @@
 # processing
 
 # choose correction menu
-sub choice($$$$$$) {
+sub choice {
 	my $hint    = shift;
 	my $l	    = shift;
 	my $c	    = shift;
 	my $r	    = shift;
 	my @choices = @{ (shift) };
 	my $align   = shift;
+	my $command = shift if @_;
 
-	@choices = @choices[0..(@choices<25?@choices-1:24)];
+	@choices = @choices[0..(@choices<26?@choices-1:25)];
 
 	debug 3, "choose correction";
 
-	my $letter = "a";					# letter counter for choice
+	my $letter  = "a";					# letter counter for choice
+	my $letters = " ";					# available choices
 	my $sp;							# space for nice presentation
 	my $s = length $c;
 	   $s = $s<length($_)?length($_):$s foreach(@choices);	# maximum choice length
@@ -518,6 +637,7 @@
 		foreach (@choices) {
 			length($l) < 3 ? ($sp = " " x  length($l))		   :
 					 ($sp = " " x (length($l) - 2).$letter." ");
+			$letters .= $letter;
 			print ($LC.$letter++.$sp.$HC.$_.(" " x ($s-length($_))).$NC.$r."\n");
 		}
 	} else {
@@ -525,25 +645,41 @@
 		foreach (@choices) {
 			length($l) < 3 ? ($sp = " " x  length($l))		   :
 					 ($sp = " " x (length($l) - 2).$letter." ");
+			$letters .= $letter;
 			print ($LC.$letter++.$sp.$HC.$_.$NC.$r."\n");
 		}
 	}
+	foreach (sort keys %$command) {
+		$letters .= $_;
+		print ($LC.$_.$CC." $$command{$_}".$NC."\n");
+	}
 
 	$letter = chr(ord($letter)-1);				# last available choice letter
 	print $LC;						# set letter color
-	0, until (<> =~ /^([ a-$letter]|$)/i);			# wait for answer
+	0, until (<> =~ /^([$letters]|$)/);			# wait for answer
 	print $NC;						# set normal color
 	return ($l.$c.$r) unless $&;				# exit if no change
 
+	if (grep(/$&/, (keys %$command))) {			# chose a special command
+		%$command = ('command' => $&);			# add it for return
+		return ($l.$c.$r);				# exit with no change
+	}
 	my $choice;
+	my $reason;
 	if ($& eq " ") {					# ask for correction
 		print "Enter correction to replace the highlighted part:\n";
 		chomp ($choice = <>);
+		if ($review eq "yes") {
+			print "Enter explanation, use displayed hint if empty:\n";
+			chomp ($reason = <>);
+		}
 	}
-	$choice = @choices[ord(lc $&)-97] unless $choice;	# set choice
+	$choice = @choices[ord(lc $&)-97] unless defined $choice;	# set choice
+	$reason ? $reason = "$comment$choice : $reason" :
+		  $reason = "$comment$choice : $hint";
 
 	print "$LC>$NC$l$choice$r\n";				# print fixed line
-	return ("$comment$choice : $hint", $l.$choice.$r);		# comment and fixed line
+	return ($reason, $l.$choice.$r);			# comment and fixed line
 }
 
 # parse one line
@@ -632,19 +768,50 @@
 
 			debug 3, "checking `$w'";
 
-			$_ = `echo "$w" | ispell -a -d $dictionary`;	# run ispell
+			next if grep(/$w/, @Spelling);
+		
+			my  %spell = ('A' => 'Accept for this session only',
+				      'I' => 'Insert in private dictionary',
+				      'U' => 'Insert lowercase in private dictionary');
+			
+			$_ = `echo "^$w" | ispell -a -d $dictionary`;	# run ispell
 			suicide "Cannot run ispell: ($?)$!" if $?;
-			/^& $w \d+ \d+: (.*)$/m;			# get correction proposal line
-			next if $1 eq $w;				# next if no proposal
-
-			my @choices = split(", ", $1);
+			my @choices;
+			my $hint;
+			s/@.*\n//;
+			if (/^(\*|\+|-)/) {				# ok, root, compound
+				next;
+			} elsif (/^(&|\?)/) {				# miss, guess
+				s/^[^:]*: //;				# keep proposal
+				chomp; chomp;				# remove two cr   // FIXME don't know why
+				@choices = split(", ");			# get corrections
+				$hint	 = "ispell: `$w'";
+			} elsif (/^#/) {				# none
+				next unless $spell_all eq "yes";
+				$hint	 = "ispell: no alternative"; 
+			} else {					# unknown
+				next;
+			}
 			
 			my $save = pos $line;				# save last match position
 				my $old_line = $line;
 			
-			my @ret = choice ("ispell $w", $l, $w, $r, \@choices, 1);
-			$line = pop @ret;				# fixed line
-			push (@comments, @ret);				# comments
+			my @ret = choice ($hint, $l, $w, $r, \@choices, 1, \%spell);
+			if (defined $spell{'command'}) {		# do something with the word
+				if      ($spell{'command'} eq 'A') {		# accept for session
+					push (@Spelling, $w);
+				} elsif ($spell{'command'} eq 'I') {		# add in dict
+					`echo "*$w" | ispell -a -d $dictionary`;# run ispell
+					suicide "Cannot run ispell: ($?)$!" if $?;
+				} elsif ($spell{'command'} eq 'U') {		# add lowercase in dict
+					$w = lc $w;				# lowercase
+					`echo "*$w" | ispell -a -d $dictionary`;# run ispell
+					suicide "Cannot run ispell: ($?)$!" if $?;
+				}
+			} else {
+				$line = pop @ret;				# fixed line
+				push (@comments, @ret);				# comments
+			}
 				
 			@ret ? pos $line = $save - length($w) :		# set last match position at the beginning of the modification
 			       pos $line = $save;			#  restore last match position if no change
@@ -777,6 +944,22 @@
 		$d = 1;
 		$review = "yes";
 	}
+	if (/^-a$/) {			# ispell stops on all unknown word
+		$d = 1;
+		$spell_all = "yes";
+	}
+	if (/^-k$/) {			# ispell stops only if there are proposals
+		$d = 1;
+		$spell_all = "no";
+	}
+	if (/^--all-words$/) {		# ispell stops on all unknown word
+		$d = 1;
+		$spell_all = "yes";
+	}
+	if (/^--known-words$/) {	# ispell stops only if there are proposals
+		$d = 1;
+		$spell_all = "no";
+	}
 } while $d;
 if (-e $_) {
 	my $file = $_;
@@ -797,12 +980,14 @@
 	   ."options:\n"
 	   ."  -q, --quiet        quiet mode\n"
 	   ."  -v                 verbose, add more for more verbosity\n"
-	   ."      --verbose      set verbosity to n\n"
+	   ."      --verbose <n>  set verbosity to n\n"
 	   ."  -i, --spell        check spelling with ispell\n"
 	   ."      --dict <lang>  use <lang> dictionary\n"
 	   ."  -n, --nospell      don't check spelling\n"
 	   ."  -r, --review       add comments (for reviewers)\n"
 	   ."  -t, --trans        don't add comments (for translators)\n"
+	   ."  -a, --all-words    stop on all words when spelling\n"
+	   ."  -k, --known-words  stop only on words with proposals when spelling\n"
 	   ."in order of appearence, last option overrides previous one if incompatible\n"
 	   ."\n"
 	   ."$me version $version\n";

Attachment: rules.tar.gz
Description: Binary data


Reply to: