2011-03-30 14:14:36 +00:00
|
|
|
#!/bin/rc
|
|
|
|
# doctype: synthesize proper command line for troff
|
|
|
|
|
2020-03-10 17:09:34 +00:00
|
|
|
if(~ $#* 0){
|
|
|
|
echo 'usage: doctype [ -n ] [ -T dev ] [ file ] ...' >[1=2]
|
|
|
|
exit usage
|
|
|
|
}
|
|
|
|
|
2011-03-30 14:14:36 +00:00
|
|
|
troff=troff
|
|
|
|
eqn=eqn
|
|
|
|
prefer=prefer
|
|
|
|
opt=''
|
|
|
|
dev=''
|
|
|
|
while(~ $1 -*){
|
|
|
|
switch($1){
|
|
|
|
case -n;
|
|
|
|
troff=nroff
|
|
|
|
eqn=neqn
|
|
|
|
prefer='prefer -n'
|
|
|
|
case -T
|
2020-03-10 16:35:06 +00:00
|
|
|
dev=-T$2
|
|
|
|
shift
|
2011-03-30 14:14:36 +00:00
|
|
|
case -*
|
|
|
|
opt=$opt' $1'
|
|
|
|
}
|
|
|
|
shift
|
|
|
|
}
|
|
|
|
ifs='
|
|
|
|
'{
|
|
|
|
files=`{echo $*}
|
|
|
|
}
|
2015-09-28 09:33:06 +00:00
|
|
|
grep -h '\$LIST|\|reference|Jp|^\.(EQ|TS|\[|TPS|PS|IS|GS|G1|GD|PP|BM|LP|BP|PI|cstart|begin|TH...)|^\.P$' $* |
|
2011-03-30 14:14:36 +00:00
|
|
|
sort -u |
|
|
|
|
awk '
|
|
|
|
BEGIN { files = "'$files'" }
|
|
|
|
/\$LIST/ { e++ }
|
|
|
|
/^\.PP/ { ms++ }
|
|
|
|
/^\.LP/ { ms++ }
|
|
|
|
/^\.EQ/ { eqn++ }
|
|
|
|
/^\.TS/ { tbl++ }
|
|
|
|
/^\.PS/ { pic++ }
|
2015-09-28 09:33:06 +00:00
|
|
|
/^\.TPS/ { tpic++; pic++ }
|
2011-03-30 14:14:36 +00:00
|
|
|
/^\.IS/ { ideal++ }
|
|
|
|
/^\.GS/ { tped++ }
|
|
|
|
/^\.G1/ { grap++; pic++ }
|
|
|
|
/^\.GD/ { dag++; pic++ }
|
|
|
|
/^\.\[/ { refer++ }
|
|
|
|
/\|reference/ { prefer++ }
|
|
|
|
/^\.cstart/ { chem++; pic++ }
|
|
|
|
/^\.begin +dformat/ { dformat++; pic++ }
|
|
|
|
/^\.TH.../ { man++ }
|
|
|
|
/^\.BM/ { lbits++ }
|
|
|
|
/^\.P$/ { mm++ }
|
|
|
|
/^\.BP/ { pictures++ }
|
|
|
|
/^\.PI/ { pictures++ }
|
|
|
|
/^\.ft *Jp|\\f\(Jp/ { nihongo++ }
|
|
|
|
END {
|
|
|
|
x = ""
|
|
|
|
if (refer) {
|
|
|
|
if (e) x = "refer/refer -e " files " | "
|
|
|
|
else x = "refer/refer " files "| "
|
|
|
|
files = ""
|
|
|
|
}
|
|
|
|
else if (prefer) { x = "cat " files "| '$prefer'| "; files = "" }
|
2015-09-28 09:33:06 +00:00
|
|
|
if (tpic) { x = x "timepic " files " | "; files = "" }
|
2011-03-30 14:14:36 +00:00
|
|
|
if (tped) { x = x "tped " files " | "; files = "" }
|
|
|
|
if (dag) { x = x "dag " files " | "; files = "" }
|
|
|
|
if (ideal) { x = x "ideal -q " files " | "; files = "" }
|
|
|
|
if (grap) { x = x "grap " files " | "; files = "" }
|
|
|
|
if (chem) { x = x "chem " files " | "; files = "" }
|
|
|
|
if (dformat) { x = x "dformat " files " | "; files = "" }
|
|
|
|
if (pic) { x = x "pic " files " | "; files = "" }
|
|
|
|
if (tbl) { x = x "tbl " files " | "; files = "" }
|
|
|
|
if (eqn) { x = x "'$eqn' '$dev' " files " | "; files = "" }
|
|
|
|
x = x "'$troff' "
|
|
|
|
if (man) x = x "-man"
|
|
|
|
else if (ms) x = x "-ms"
|
|
|
|
else if (mm) x = x "-mm"
|
|
|
|
if (lbits) x = x " -mbits"
|
|
|
|
if (pictures) x = x " -mpictures"
|
|
|
|
if (nihongo) x = x " -mnihongo"
|
|
|
|
x = x " '$opt' '$dev' " files
|
|
|
|
print x
|
|
|
|
}'
|