doctype 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/rc
  2. # doctype: synthesize proper command line for troff
  3. troff=troff
  4. eqn=eqn
  5. prefer=prefer
  6. opt=''
  7. dev=''
  8. while(~ $1 -*){
  9. switch($1){
  10. case -n;
  11. troff=nroff
  12. eqn=neqn
  13. prefer='prefer -n'
  14. case -T
  15. dev=$1
  16. case -*
  17. opt=$opt' $1'
  18. }
  19. shift
  20. }
  21. ifs='
  22. '{
  23. files=`{echo $*}
  24. }
  25. grep -h '\$LIST|\|reference|Jp|^\.(EQ|TS|\[|PS|IS|GS|G1|GD|PP|BM|LP|BP|PI|cstart|begin|TH...|TI)|^\.P$' $* |
  26. sort -u |
  27. awk '
  28. BEGIN { files = "'$"files'" }
  29. /\$LIST/ { e++ }
  30. /^\.PP/ { ms++ }
  31. /^\.LP/ { ms++ }
  32. /^\.EQ/ { eqn++ }
  33. /^\.TS/ { tbl++ }
  34. /^\.PS/ { pic++ }
  35. /^\.IS/ { ideal++ }
  36. /^\.GS/ { tped++ }
  37. /^\.G1/ { grap++; pic++ }
  38. /^\.GD/ { dag++; pic++ }
  39. /^\.\[/ { refer++ }
  40. /\|reference/ { prefer++ }
  41. /^\.cstart/ { chem++; pic++ }
  42. /^\.begin +dformat/ { dformat++; pic++ }
  43. /^\.TH.../ { man++ }
  44. /^\.BM/ { lbits++ }
  45. /^\.P$/ { mm++ }
  46. /^\.BP/ { pictures++ }
  47. /^\.PI/ { pictures++ }
  48. /^\.TI/ { mcs++ }
  49. /^\.ft *Jp|\\f\(Jp/ { nihongo++ }
  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 (mcs) x = x " -mcs"
  72. if (lbits) x = x " -mbits"
  73. if (pictures) x = x " -mpictures"
  74. if (nihongo) x = x " -mnihongo"
  75. x = x " '$opt' '$dev' " files
  76. print x
  77. }'