/usr/bin/ispell-wrapper is in dictionaries-common 1.26.3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | #!/usr/bin/perl -w
use strict;
use Debian::DictionariesCommon q(:all);
use Getopt::Long;
Getopt::Long::Configure("pass_through","no_auto_abbrev");
# Autoflush output buffers
$|=1;
my $class = "ispell";
my $dictionaries = loaddb ($class);
my $emacsen;
my $regexp;
my $dryrun;
# -------------------------------------------------
sub isoconv {
# -------------------------------------------------
# Function to convert ISO-8859-1 (latin1) accented characters to
# non-accented one. Of course, this only works for west European
# languages. We might try to find a more general solution based on
# the current locale character set.
# -------------------------------------------------
my $s = shift;
$s =~ y{A-ZÁÉÍÓÚÝáéíóúýÀÈÌÒÙàèìòùÂÊÎÔÛâêîôûÄËÏÖÜäëïößüÿÃÇÐÑÕãçñõÅÆØåæø}
{a-zaeiouyaeiouyaeiouaeiouaeiouaeiouaeiouaeiosuyacdnoacnoaeoaeo};
return $s;
}
# -------------------------------------------------
sub try_emacsen () {
# -------------------------------------------------
# Function to try getting $lang after emacsen name
# -------------------------------------------------
my $emacsen = shift;
return unless $emacsen;
my %available_emacsen = ();
foreach my $lang (keys %$dictionaries) {
my $language = $dictionaries->{$lang};
my $hashname = $language->{"hash-name"};
my $emacsenname = exists $language->{"emacsen-name"} ?
$language->{"emacsen-name"} : $hashname;
return $lang if ( lc($emacsen) eq lc($emacsenname) );
$available_emacsen{$emacsenname}++;
}
die "$0: \"$emacsen\" does not match any available emacs dict value:\n "
. join("\n ", sort keys %available_emacsen) . "\n";
}
# -------------------------------------------------
sub try_regexp () {
# -------------------------------------------------
# Function to try getting $lang after $regexp
# -------------------------------------------------
my $regexp = shift;
return unless $regexp;
my $guess;
my %regexp_matches = ();
$regexp = isoconv ($regexp);
foreach my $key ( keys %$dictionaries ) {
$_ = isoconv ( $key );
if ( /$regexp/ ) {
$regexp_matches{$key}++;
$guess = $key;
}
}
die "$0: No installed language matched `$regexp'\n" unless $guess;
if ( scalar keys %regexp_matches == 1) {
return $guess;
} else {
die ("$0: More than one installed languages matched `$regexp':\n "
. join ("\n ", sort keys %regexp_matches) . "\n");
}
}
# --------------------------------------------------------------------
# Now the main program
# --------------------------------------------------------------------
GetOptions ('emacs=s' => \$emacsen,
'language=s' => \$regexp,
'dry-run' => \$dryrun);
die " ispell-wrapper is a wrapper to ispell, but ispell is not installed.\n"
unless ( -x "/usr/bin/ispell" );
$regexp = $ENV{ISPELLDEFAULT} unless $regexp;
$regexp =~ s/([^\\]|^)(\(|\))/$1\\$2/g if $regexp; # Make sure () are escaped
# In the POD section below there is an extensive description on the
# priority order for determining the ispell language.
my $lang = &try_emacsen($emacsen)
|| &try_regexp ($regexp)
|| &getuserdefault ()
|| &dico_getsysdefault ("ispell");
print STDERR " Warning: --language=$regexp will be overriden by
--emacs=$emacsen setting\n\n"
if ( defined $lang && $regexp && $emacsen );
my $ispell_wrapper_args = "";
$ispell_wrapper_args = dico_get_spellchecker_params($class,$dictionaries->{$lang})
if ( $lang && defined $dictionaries->{$lang});
# Ignore $lang results if -d is explicitly set from commandline
foreach ( @ARGV ) {
if ( /^\-d/ ){
$ispell_wrapper_args = "";
last;
}
}
my $cli_opts = join(' ',@ARGV);
print STDERR "Warning: \'$lang\' values overriden with \'$cli_opts\'\n"
if ( not $ispell_wrapper_args && defined $lang );
my $command_to_run = "ispell $ispell_wrapper_args $cli_opts";
if ( $dryrun ){
print "--\n$command_to_run\n--\n";
} else {
exec $command_to_run;
}
# Local Variables:
# perl-indent-level: 2
# End:
__END__
=head1 NAME
B<ispell-wrapper> - smart wrapper for ispell
=head1 SYNOPSIS
ispell-wrapper [--emacs=name] [--language=regexp] [--dry-run] [ispell options] file
Options (all long only options):
--emacs=name Set the language to use by emacs dict name
--language=regexp Set the language to use by name
--dry-run Only show what would have done
=head1 DESCRIPTION
B<ispell-wrapper> is a wrapper script for ispell intended to be used
in a Debian system in conjunction with the infrastructure introduced by
the dictionaries-common package. Option --dry-run will show the string
to be run without doing anything else.
It automatically sets the B<-d>, B<-w>, and B<-T> options to ispell as a
function of the chosen language. Of course, this only works for dictionary
packages that comply with the above mentioned Policy.
Here is how the language is defined (in order of priority):
=over
=item 1)
By matching the emacs dict name given in --emacs option to the name of
one of the emacs dicts names provided by installed languages in the
system. This match must be exact (although is case insensitive).
Note that this will override any value given in the --language option.
=item 2)
By matching the regexp given in option --language to the list of
installed languages in the system.
=item 3)
By matching the regexp stored in the environment variable
ISPELLDEFAULT to the list of installed languages in the system.
=item 4)
By using the value stored in the user-specific file ~/.ispell-default
(use select-default-iwrap(1) to set it).
=item 5)
By using the value stored in the site-wide file
/etc/dictionaries-common/ispell-default (use select-default-ispell(8)
as superuser to set it).
=back
Note: regexp matches are case-insensitive and the ISO-8859-1 special
characters are transformed into their ASCII equivalents. German
ess-zet is equivalent to the character "s" and the ae ligature to the
character "e".
=head1 EXAMPLE
Let us say that the following dictionaries are installed in the system
(as appearing in the Debconf question at installation time):
castellano (Spanish TeX mode)
castellano8 (Spanish 8 bit)
portuguE<ecirc>s (European Portuguese)
portuguE<ecirc>s brasileiro (Brazilian Portuguese)
Choosing the regexp (either in the --language option or in the
environment variable ISPELLDEFAULT) to be "span" will yield an error,
since two languages will match ("castellano" and "castellano8").
However, if the regexp is "span.*8", the language "castellano8
(Spanish 8 bit)" will be chosen.
=head1 ENVIRONMENT
=over
=item ISPELLDEFAULT
Regexp that matches the name of the default language to use, if no
--language option is given.
=back
=head1 FILES
=over
=item $HOME/.ispell-default
Contains the name of the language to use, if no --language option is
given or if the ISPELLDEFAULT environment variable is not set. This
is a user-specific choice.
=item /etc/dictionaries-common/ispell-default
Name of the language to use when everything above is not set. This is
a system-wide setting.
=back
=head1 SEE ALSO
select-default-ispell(8), select-default-iwrap(1)
=head1 AUTHORS
Rafael Laboissiere
=cut
|