2 # grog -- guess options for groff command
3 # Inspired by doctype script in Kernighan & Pike, Unix Programming
4 # Environment, pp 306-8.
9 push(@command, "groff");
11 while ($ARGV[0] =~ /^-./) {
18 foreach $arg (@ARGV) {
27 local($filename, $level) = @_;
30 if (!open(FILE
, $filename eq "-" ?
$filename : "< $filename")) {
31 print STDERR
"$prog: can't open \`$filename': $!\n";
45 if (!/^\./ || /^\.[0-9]/) {
56 elsif (/^\.PS([ 0-9.<].*)?$/) {
57 if (/^\.PS\s*<\s*(\S+)/) {
64 if (!/^\./ || /^\.ps/) {
70 elsif (/^\.R1/ || /^\.\[/) {
80 elsif (/^\.(PH|SA)/) {
89 elsif (/^\.([pnil]p|sh)/) {
95 elsif (/^\.(Tp|Dp|De|Cx|Cl)/) {
98 # In the old version of -mdoc `Oo' is a toggle, in the new it's
111 &process
($_, $level + 1) unless /\\/ || $_ eq "";
117 if ($pic || $tbl || $eqn || $grn || $refer) {
119 $s .= "s" if $soelim;
129 push(@command, "-me");
131 elsif ($SH > 0 && $TH > 0) {
132 push(@command, "-man");
135 push(@command, "-ms");
137 elsif ($P > 0 || $mm > 0) {
138 push(@command, "-mm");
141 push(@command, ($mdoc_old || $Oo > 0) ?
"-mdoc.old" : "-mdoc");
144 push(@command, "--") if @ARGV && $ARGV[0] =~ /^-./;
146 push(@command, @ARGV);
148 # We could implement an option to execute the command here.
151 next unless /[\$\\\"\';&()|<> \t\n]/;
156 print join(' ', @command), "\n";