3 # Include polygen output in a page
6 package IkiWiki::Plugin::polygen;
14 hook(type => "preprocess", id => "polygen", call => \&preprocess);
17 sub preprocess (@) { #{{{
19 my $grammar = ($params{grammar} or 'polygen');
20 my $symbol = ($params{symbol} or undef);
23 $grammar =~ IkiWiki::basename($grammar);
24 $grammar =~ s/[^A-Za-z0-9]//g;
25 $grammar =~ s/\.grm$//;
27 $symbol =~ s/[^A-Za-z0-9]//g if defined $symbol;
28 $symbol = IkiWiki::possibly_foolish_untaint($symbol) if defined $symbol;
30 my $grmfile = '/usr/share/polygen/ita/polygen.grm';
31 if (! -d '/usr/share/polygen') {
32 error gettext("polygen not installed");
35 if (substr($File::Find::name, -length($grammar)) eq $grammar) {
36 $grmfile = IkiWiki::possibly_foolish_untaint($File::Find::name);
40 }, '/usr/share/polygen');
43 if (defined $symbol) {
44 $res = `polygen -S $symbol $grmfile 2>/dev/null`;
47 $res = `polygen $grmfile 2>/dev/null`;
51 error gettext("command failed");
54 # Strip trailing spaces and newlines so that we flow well with the