nroff.sh revision 76025
1#!/bin/sh
2# Emulate nroff with groff.
3# $FreeBSD: head/contrib/groff/src/roff/nroff/nroff.sh 76025 2001-04-26 12:29:12Z ru $
4
5prog="$0"
6# Default device.
7# First try the "locale charmap" command, because it's most reliable.
8# On systems where it doesn't exist, look at the environment variables.
9case "`#locale charmap 2>/dev/null`" in
10  UTF-8)
11    T=-Tutf8 ;;
12  ISO-8859-1)
13    T=-Tlatin1 ;;
14  IBM-1047)
15    T=-Tcp1047 ;;
16  *)
17    case "${LC_ALL-${LC_CTYPE-${LANG}}}" in
18      *.UTF-8)
19        T=-Tutf8 ;;
20      iso_8859_1 | *.ISO-8859-1 | *.ISO_8859-1)
21        T=-Tlatin1 ;;
22      *.IBM-1047)
23        T=-Tcp1047 ;;
24      *.KOI8-R)
25        T=-Tkoi8-r ;;
26      *)
27        case "$LESSCHARSET" in
28          utf-8)
29            T=-Tutf8 ;;
30          latin1)
31            T=-Tlatin1 ;;
32          cp1047)
33            T=-Tcp1047 ;;
34          *)
35            T=-Tascii ;;
36          esac ;;
37     esac ;;
38esac
39opts=
40safer=-S
41
42# `for i; do' doesn't work with some versions of sh
43
44for i
45  do
46  case $1 in
47    -h)
48      opts="$opts -P-h" ;;
49    -[eq] | -s*)
50      # ignore these options
51      ;;
52    -[mrnoT])
53      echo "$prog: option $1 requires an argument" >&2
54      exit 1 ;;
55    -[ipt] | -[mrno]*)
56      opts="$opts $1" ;;
57    -Tascii | -Tlatin1 | -Tkoi8-r | -Tutf8 | -Tcp1047)
58      T=$1 ;;
59    -T*)
60      # ignore other devices
61      ;;
62    -S)
63      # safer behaviour
64      safer=-S ;;
65    -U)
66      # unsafe behaviour
67      safer=-U ;;
68    -u*)
69      # Solaris 2.2 `man' uses -u0; ignore it,
70      # since `less' and `more' can use the emboldening info.
71      ;;
72    -v | --version)
73      echo "GNU nroff (groff) version @VERSION@"
74      exit 0 ;;
75    --help)
76      echo "usage: nroff [-h] [-i] [-mNAME] [-nNUM] [-oLIST] [-p] [-rCN] [-t] [-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
90done
91
92# This shell script is intended for use with man, so warnings are
93# probably not wanted.  Also load nroff-style character definitions.
94
95: ${GROFF_BIN_PATH=@BINDIR@}
96export GROFF_BIN_PATH
97PATH=$GROFF_BIN_PATH:$PATH groff $safer -Wall -mtty-char $T $opts ${1+"$@"}
98
99# eof
100