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);
29 my $grammar = ($params{grammar} or 'polygen');
30 my $symbol = ($params{symbol} or undef);
31 my $options = ($config{deterministic} ? '-seed 42' : '');
34 $grammar =~ IkiWiki::basename($grammar);
35 $grammar =~ s/[^A-Za-z0-9]//g;
36 $grammar =~ s/\.grm$//;
38 $symbol =~ s/[^A-Za-z0-9]//g if defined $symbol;
39 $symbol = IkiWiki::possibly_foolish_untaint($symbol) if defined $symbol;
41 my $grmfile = '/usr/share/polygen/ita/polygen.grm';
42 if (! -d '/usr/share/polygen') {
43 error gettext("polygen not installed");
46 if (substr($File::Find::name, -length($grammar)) eq $grammar) {
47 $grmfile = IkiWiki::possibly_foolish_untaint($File::Find::name);
51 }, '/usr/share/polygen');
54 if (defined $symbol) {
55 $res = `polygen -S $symbol $options $grmfile 2>/dev/null`;
58 $res = `polygen $options $grmfile 2>/dev/null`;
62 error gettext("command failed");
65 # Strip trailing spaces and newlines so that we flow well with the