Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / groff / src / roff / nroff / nroff.sh
1 #!/bin/sh
2 # Emulate nroff with groff.
3 # $FreeBSD: src/contrib/groff/src/roff/nroff/nroff.sh,v 1.11.2.3 2003/02/14 15:22:08 ru Exp $
4
5 prog="$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.
9 case "`#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-15)
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 ;;
38 esac
39 opts=
40
41 # `for i; do' doesn't work with some versions of sh
42
43 for i
44   do
45   case $1 in
46     -c)
47       opts="$opts -P-c" ;;
48     -h)
49       opts="$opts -P-h" ;;
50     -[eq] | -s*)
51       # ignore these options
52       ;;
53     -[mrnoT])
54       echo "$prog: option $1 requires an argument" >&2
55       exit 1 ;;
56     -[iptSUC] | -[mrno]*)
57       opts="$opts $1" ;;
58     -Tascii | -Tlatin1 | -Tkoi8-r | -Tutf8 | -Tcp1047)
59       T=$1 ;;
60     -T*)
61       # ignore other devices
62       ;;
63     -u*)
64       # Solaris 2.2 `man' uses -u0; ignore it,
65       # since `less' and `more' can use the emboldening info.
66       ;;
67     -v | --version)
68       echo "GNU nroff (groff) version @VERSION@"
69       exit 0 ;;
70     --help)
71       echo "usage: nroff [-cChipt] [-mNAME] [-nNUM] [-oLIST] [-rCN] [-Tname] [FILE...]"
72       exit 0 ;;
73     --)
74       shift
75       break ;;
76     -)
77       break ;;
78     -*)
79       echo "$prog: invalid option $1" >&2
80       exit 1 ;;
81     *)
82       break ;;
83   esac
84   shift
85 done
86
87 # This shell script is intended for use with man, so warnings are
88 # probably not wanted.  Also load nroff-style character definitions.
89
90 : ${GROFF_BIN_PATH=@BINDIR@}
91 export GROFF_BIN_PATH
92 PATH=$GROFF_BIN_PATH:$PATH groff -mtty-char $T $opts ${1+"$@"}
93
94 # eof