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