Blob


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