3 # Include polygen output in a page
6 package IkiWiki::Plugin::polygen;
14 hook(type => "getsetup", id => "polygen", call => \&getsetup);
15 hook(type => "preprocess", id => "polygen", call => \&preprocess);
18 sub getsetup () { #{{{
26 sub preprocess (@) { #{{{
28 my $grammar = ($params{grammar} or 'polygen');
29 my $symbol = ($params{symbol} or undef);
32 $grammar =~ IkiWiki::basename($grammar);
33 $grammar =~ s/[^A-Za-z0-9]//g;
34 $grammar =~ s/\.grm$//;
36 $symbol =~ s/[^A-Za-z0-9]//g if defined $symbol;
37 $symbol = IkiWiki::possibly_foolish_untaint($symbol) if defined $symbol;
39 my $grmfile = '/usr/share/polygen/ita/polygen.grm';
40 if (! -d '/usr/share/polygen') {
41 error gettext("polygen not installed");
44 if (substr($File::Find::name, -length($grammar)) eq $grammar) {
45 $grmfile = IkiWiki::possibly_foolish_untaint($File::Find::name);
49 }, '/usr/share/polygen');
52 if (defined $symbol) {
53 $res = `polygen -S $symbol $grmfile 2>/dev/null`;
56 $res = `polygen $grmfile 2>/dev/null`;
60 error gettext("command failed");
63 # Strip trailing spaces and newlines so that we flow well with the