Blob


1 #!/usr/bin/env rc
2 # doctype: synthesize proper command line for troff
4 troff=troff
5 eqn=eqn
6 prefer=prefer
7 opt=''
8 dev=''
9 while(~ $1 -*){
10 switch($1){
11 case -n;
12 troff=nroff
13 eqn=neqn
14 prefer='prefer -n'
15 case -T
16 dev=$1
17 case -*
18 opt=$opt' $1'
19 }
20 shift
21 }
22 ifs='
23 '{
24 files=`{echo $*}
25 }
26 9grep -h '\$LIST|\|reference|^\.(EQ|TS|\[|PS|IS|GS|G1|GD|PP|BM|LP|BP|PI|cstart|begin|TH...)|^\.P$' $* |
27 sort -u |
28 awk '
29 BEGIN { files = "'$files'" }
30 /\$LIST/ { e++ }
31 /^\.PP/ { ms++ }
32 /^\.LP/ { ms++ }
33 /^\.EQ/ { eqn++ }
34 /^\.TS/ { tbl++ }
35 /^\.PS/ { pic++ }
36 /^\.IS/ { ideal++ }
37 /^\.GS/ { tped++ }
38 /^\.G1/ { grap++; pic++ }
39 /^\.GD/ { dag++; pic++ }
40 /^\.\[/ { refer++ }
41 /\|reference/ { prefer++ }
42 /^\.cstart/ { chem++; pic++ }
43 /^\.begin +dformat/ { dformat++; pic++ }
44 /^\.TH.../ { man++ }
45 /^\.BM/ { lbits++ }
46 /^\.P$/ { mm++ }
47 /^\.BP/ { pictures++ }
48 /^\.PI/ { pictures++ }
49 END {
50 x = ""
51 if (refer) {
52 if (e) x = "refer -e " files " | "
53 else x = "refer " files "| "
54 files = ""
55 }
56 else if (prefer) { x = "cat " files "| '$prefer'| "; files = "" }
57 if (tped) { x = x "tped " files " | "; files = "" }
58 if (dag) { x = x "dag " files " | "; files = "" }
59 if (ideal) { x = x "ideal -q " files " | "; files = "" }
60 if (grap) { x = x "grap " files " | "; files = "" }
61 if (chem) { x = x "chem " files " | "; files = "" }
62 if (dformat) { x = x "dformat " files " | "; files = "" }
63 if (pic) { x = x "pic " files " | "; files = "" }
64 if (tbl) { x = x "tbl " files " | "; files = "" }
65 if (eqn) { x = x "'$eqn' '$dev' " files " | "; files = "" }
66 x = x "'$troff' "
67 if (man) x = x "-man"
68 else if (ms) x = x "-ms"
69 else if (mm) x = x "-mm"
70 if (lbits) x = x "-mbits"
71 if (pictures) x = x " -mpictures"
72 x = x " '$opt' '$dev' " files
73 print x
74 }'