2 # grog -- guess options for groff command
3 # Inspired by doctype script in Kernighan & Pike, Unix Programming
4 # Environment, pp 306-8.
11 push(@command, "groff");
13 while ($ARGV[0] =~ /^-./) {
15 $sp = "" if $arg eq "-C";
16 &usage(0) if $arg eq "-v" || $arg eq "--version";
17 &help() if $arg eq "--help";
22 @ARGV = ('-') unless @ARGV;
23 foreach $arg (@ARGV) {
28 local($filename, $level) = @_;
31 if (!open(FILE, $filename eq "-" ? $filename : "< $filename")) {
32 print STDERR "$prog: can't open \`$filename': $!\n";
46 if (!/^\./ || /^\.[0-9]/) {
66 elsif (/^\.PS$sp([ 0-9.<].*)?$/) {
67 if (/^\.PS\s*<\s*(\S+)/) {
74 if (!/^\./ || /^\.ps/) {
92 elsif (/^\.[PLI]P$sp/) {
98 elsif (/^\.(PH|SA)$sp/) {
107 elsif (/^\.([pnil]p|sh)$sp/) {
113 elsif (/^\.(Tp|Dp|De|Cx|Cl)$sp/) {
116 # In the old version of -mdoc `Oo' is a toggle, in the new it's
123 # The test for `Oo' and `Oc' not starting a line (as allowed by the
124 # new implementation of -mdoc) is not complete; it assumes that
125 # macro arguments are well behaved, i.e., "" is used within "..." to
126 # indicate a doublequote as a string element, and weird features
127 # like `.foo a"b' are not used.
128 elsif (/^\..* Oo( |$)/) {
142 elsif (/^\..* Oc( |$)/) {
151 elsif (/^\.(PRINTSTYLE|START)$sp/) {
159 &process($_, $level + 1) unless /\\/ || $_ eq "";
166 local($exit_status) = $_;
167 print "GNU grog (groff) version @VERSION@\n";
172 print "usage: grog [ option ...] [files...]\n";
176 $refer ||= $refer_open && $refer_close;
178 if ($pic || $tbl || $eqn || $grn || $grap || $refer) {
180 $s .= "s" if $soelim;
182 # grap must be run before pic
192 push(@command, "-me");
194 elsif ($SH > 0 && $TH > 0) {
195 push(@command, "-man");
198 push(@command, "-mom");
201 push(@command, "-ms");
203 elsif ($P > 0 || $mm > 0) {
204 push(@command, "-mm");
207 push(@command, ($mdoc_old || $Oo > 0) ? "-mdoc-old" : "-mdoc");
210 push(@command, "--") if @ARGV && $ARGV[0] =~ /^-./;
212 push(@command, @ARGV);
214 # We could implement an option to execute the command here.
217 next unless /[\$\\\"\';&()|<> \t\n]/;
222 print join(' ', @command), "\n";