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]/) {
50 elsif (/^\.PS([ 0-9.<].*)?$/) {
51 if (/^\.PS\s*<\s*(\S+)/) {
58 if (!/^\./ || /^\.ps/) {
64 elsif (/^\.R1/ || /^\.\[/) {
74 elsif (/^\.(PH|SA)/) {
83 elsif (/^\.([pnil]p|sh)/) {
89 elsif (/^\.(Tp|Dp|De|Cx|Cl)/) {
92 # In the old version of -mdoc `Oo' is a toggle, in the new it's
105 &process($_, $level + 1) unless /\\/ || $_ eq "";
111 if ($pic || $tbl || $eqn || $refer) {
113 $s .= "s" if $soelim;
122 push(@command, "-me");
124 elsif ($SH > 0 && $TH > 0) {
125 push(@command, "-man");
128 push(@command, "-ms");
130 elsif ($P > 0 || $mm > 0) {
131 push(@command, "-mm");
134 push(@command, ($mdoc_old || $Oo > 0) ? "-mdoc.old" : "-mdoc");
137 push(@command, "--") if @ARGV && $ARGV[0] =~ /^-./;
139 push(@command, @ARGV);
141 # We could implement an option to execute the command here.
144 next unless /[\$\\\"\';&()|<> \t\n]/;
149 print join(' ', @command), "\n";