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