blob: 5208a44ec5c9a342ff798a3ec8401f240f8562ba (
plain)
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
|
#!/usr/bin/perl
#
# Include polygen output in a page
#
# by Enrico Zini
package IkiWiki::Plugin::polygen;
use warnings;
use strict;
use IkiWiki 2.00;
use File::Find;
sub import { #{{{
hook(type => "preprocess", id => "polygen", call => \&preprocess);
} # }}}
sub preprocess (@) { #{{{
my %params=@_;
my $grammar = ($params{grammar} or 'polygen');
my $symbol = ($params{symbol} or undef);
# Sanitize parameters
$grammar =~ IkiWiki::basename($grammar);
$grammar =~ s/[^A-Za-z0-9]//g;
$grammar =~ s/\.grm$//;
$grammar .= '.grm';
$symbol =~ s/[^A-Za-z0-9]//g if defined $symbol;
$symbol = IkiWiki::possibly_foolish_untaint($symbol) if defined $symbol;
my $grmfile = '/usr/share/polygen/ita/polygen.grm';
if (! -d '/usr/share/polygen') {
return "[[".gettext("polygen not installed")."]]";
}
find({wanted => sub {
if (substr($File::Find::name, -length($grammar)) eq $grammar) {
$grmfile = IkiWiki::possibly_foolish_untaint($File::Find::name);
}
},
no_chdir => 1,
}, '/usr/share/polygen');
my $res;
if (defined $symbol) {
$res = `polygen -S $symbol $grmfile 2>/dev/null`;
}
else {
$res = `polygen $grmfile 2>/dev/null`;
}
if ($?) {
$res="[[".gettext("polygen failed")."]]";
}
# Strip trailing spaces and newlines so that we flow well with the
# markdown text
$res =~ s/\s*$//;
return $res;
} # }}}
1
|