File: sgml-spell-checker.in

package info (click to toggle)
sgml-spell-checker 0.0.20040919-3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, lenny, sid, squeeze, stretch, wheezy
  • size: 148 kB
  • sloc: sh: 173; perl: 109; makefile: 2
file content (99 lines) | stat: -rw-r--r-- 2,226 bytes parent folder | download | duplicates (3)
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
#!@PERL@ -w
# -*- perl -*-

use FileHandle;
use Getopt::Long;
use IPC::Open2;
use File::Basename;

my $aspell = $ENV{'ASPELL'} || '@ASPELL@';
my $sgmlspl = $ENV{'SGMLSPL'} || '@SGMLSPL@';

my $debug = '';
my $suggestions = '';
my $language = '';
my $dtd = '';
GetOptions
  ('debug!' => \$debug,
   'suggestions!' => \$suggestions,
   'language=s' => \$language,
   'dictionary=s' => \@dicts,
   'dtd=s' => \$dtd,

   'help' => \&help);

# If the paths are relative, prepend ./ so that aspell doesn't try to
# look them up in its path.
@dicts = map { $_ !~ m,^/, ? "./$_" : $_ } @dicts;

my $opts = '';
$opts = "@pkgdatadir@/${dtd}-exclusion-list.txt" if $dtd;
open(INSTREAM, "$sgmlspl @pkgdatadir@/sgml-spell-filter-spec.pl $opts |") or die;

$opts = '';
$opts .= " --add-extra-dicts='$_'" foreach (@dicts);
$opts .= " --language-tag=$language" if $language;

$pid = open2(*Reader, *Writer, "$aspell --ignore=2 $opts --sug-mode=fast pipe");

<Reader>;			# eat header
print Writer "!\n";		# enter terse mode

my $lineinfo = 0;

while (defined($_ = <INSTREAM>)) {
    chomp;

    /^\s*$/ && next;
    /^\# (.*)/ && do {
        $lineinfo = $1;
        next;
    };
    /^\^/ || die "invalid input line #$." . ($debug ? $_ : "") . "\n";

    print Writer "$_\n";

    while ($got = <Reader>) {
        chomp($got);
        last if $got eq '';

        $got =~ /^\& (\S+) \S+ \S+: (.*)/ && do {
            if ($suggestions) {
                print "$lineinfo: $1   ($2)\n";
            } else {
                print "$lineinfo: $1\n";
            }
        };
        $got =~ /^\# (\S+)/ && do {
            print "$lineinfo: $1\n";
        };
    }
}

close INSTREAM;

close Reader;
close Writer;
waitpid $pid, 0;


sub help {
    my $me = basename($0);

    print <<END;
$me is an SGML spell-checker.

Usage:
  nsgmls -l ARGS... | $0 [OPTION]...

Options:
  --debug               Debug mode
  --language=LANG       Language of the document (e.g., en or en_US)
  --suggestions         Show suggestions for misspelled words
  --dictionary=FILE     Use additional dictionary file
                        (may be used multiple times)
  --dtd=NAME            Use exclusion list for specified DTD (e.g., docbook)

END
    exit 0;
}