/contrib/groff/src/roff/nroff/nroff.sh

https://bitbucket.org/freebsd/freebsd-head/ · Shell · 106 lines · 80 code · 8 blank · 18 comment · 1 complexity · 855ff9b9432ecb160c40389879b17d68 MD5 · raw file

  1. #! /bin/sh
  2. # Emulate nroff with groff.
  3. # $FreeBSD$
  4. prog="$0"
  5. # Default device.
  6. # First try the "locale charmap" command, because it's most reliable.
  7. # On systems where it doesn't exist, look at the environment variables.
  8. case "`exec 2>/dev/null ; locale charmap`" in
  9. UTF-8)
  10. T=-Tutf8 ;;
  11. ISO*8859-1 | ISO*8859-15)
  12. T=-Tlatin1 ;;
  13. KOI8-R)
  14. T=-Tkoi8-r ;;
  15. IBM-1047)
  16. T=-Tcp1047 ;;
  17. *)
  18. case "${LC_ALL-${LC_CTYPE-${LANG}}}" in
  19. *.UTF-8)
  20. T=-Tutf8 ;;
  21. iso_8859_1 | *.ISO-8859-1 | *.ISO8859-1 | \
  22. iso_8859_15 | *.ISO-8859-15 | *.ISO8859-15)
  23. T=-Tlatin1 ;;
  24. *.KOI8-R)
  25. T=-Tkoi8-r ;;
  26. *.IBM-1047)
  27. T=-Tcp1047 ;;
  28. *)
  29. case "$LESSCHARSET" in
  30. utf-8)
  31. T=-Tutf8 ;;
  32. latin1)
  33. T=-Tlatin1 ;;
  34. koi8-r)
  35. T=-Tkoi8-r ;;
  36. cp1047)
  37. T=-Tcp1047 ;;
  38. *)
  39. T=-Tascii ;;
  40. esac ;;
  41. esac ;;
  42. esac
  43. opts=
  44. # `for i; do' doesn't work with some versions of sh
  45. for i
  46. do
  47. case $1 in
  48. -c)
  49. opts="$opts -P-c" ;;
  50. -h)
  51. opts="$opts -P-h" ;;
  52. -[eq] | -s*)
  53. # ignore these options
  54. ;;
  55. -[dMmrnoT])
  56. echo "$prog: option $1 requires an argument" >&2
  57. exit 1 ;;
  58. -[iptSUC] | -[dMmrno]*)
  59. opts="$opts $1" ;;
  60. -Tascii | -Tlatin1 | -Tkoi8-r | -Tutf8 | -Tcp1047)
  61. T=$1 ;;
  62. -T*)
  63. # ignore other devices
  64. ;;
  65. -u*)
  66. # Solaris 2.2 through at least Solaris 9 `man' invokes
  67. # `nroff -u0 ... | col -x'. Ignore the -u0,
  68. # since `less' and `more' can use the emboldening info.
  69. # However, disable SGR, since Solaris `col' mishandles it.
  70. opts="$opts -P-c" ;;
  71. -v | --version)
  72. echo "GNU nroff (groff) version @VERSION@"
  73. exit 0 ;;
  74. --help)
  75. echo "usage: nroff [-CchipStUv] [-dCS] [-MDIR] [-mNAME] [-nNUM] [-oLIST]"
  76. echo " [-rCN] [-Tname] [FILE...]"
  77. exit 0 ;;
  78. --)
  79. shift
  80. break ;;
  81. -)
  82. break ;;
  83. -*)
  84. echo "$prog: invalid option $1" >&2
  85. exit 1 ;;
  86. *)
  87. break ;;
  88. esac
  89. shift
  90. done
  91. # Set up the `GROFF_BIN_PATH' variable
  92. # to be exported in the current `GROFF_RUNTIME' environment.
  93. @GROFF_BIN_PATH_SETUP@
  94. export GROFF_BIN_PATH
  95. # This shell script is intended for use with man, so warnings are
  96. # probably not wanted. Also load nroff-style character definitions.
  97. PATH="$GROFF_RUNTIME$PATH" groff -mtty-char $T $opts ${1+"$@"}
  98. # eof