groff: update vendor branch to v1.20.1
[dragonfly.git] / contrib / groff / src / roff / nroff / nroff.sh
CommitLineData
465b256c 1#! /bin/sh
92d0a6a6 2# Emulate nroff with groff.
4d3e9548
JL
3#
4# Copyright (C) 1992, 1993, 1994, 1999, 2000, 2001, 2002, 2003,
5# 2004, 2005, 2007, 2009
6# Free Software Foundation, Inc.
7#
8# Written by James Clark, maintained by Werner Lemberg.
9
10# This file is of `groff'.
11
12# `groff' is free software; you can redistribute it and/or modify it
13# under the terms of the GNU General Public License (GPL) as published
14# by the Free Software Foundation, either version 3 of the License, or
15# (at your option) any later version.
16
17# `groff' is distributed in the hope that it will be useful, but
18# WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20# General Public License for more details.
21
22# You should have received a copy of the GNU General Public License
23# along with this program. If not, see <http://www.gnu.org/licenses/>.
92d0a6a6
JR
24
25prog="$0"
4d3e9548 26
92d0a6a6 27# Default device.
4d3e9548
JL
28
29# Check the GROFF_TYPESETTER environment variable.
30Tenv=$GROFF_TYPESETTER
31
32# Try the `locale charmap' command first because it is most reliable.
92d0a6a6
JR
33# On systems where it doesn't exist, look at the environment variables.
34case "`exec 2>/dev/null ; locale charmap`" in
35 UTF-8)
4d3e9548 36 Tloc=utf8 ;;
465b256c 37 ISO-8859-1 | ISO-8859-15)
4d3e9548 38 Tloc=latin1 ;;
92d0a6a6 39 IBM-1047)
4d3e9548 40 Tloc=cp1047 ;;
92d0a6a6
JR
41 *)
42 case "${LC_ALL-${LC_CTYPE-${LANG}}}" in
43 *.UTF-8)
4d3e9548 44 Tloc=utf8 ;;
465b256c
JR
45 iso_8859_1 | *.ISO-8859-1 | *.ISO8859-1 | \
46 iso_8859_15 | *.ISO-8859-15 | *.ISO8859-15)
4d3e9548 47 Tloc=latin1 ;;
92d0a6a6 48 *.IBM-1047)
4d3e9548 49 Tloc=cp1047 ;;
92d0a6a6
JR
50 *)
51 case "$LESSCHARSET" in
52 utf-8)
4d3e9548 53 Tloc=utf8 ;;
92d0a6a6 54 latin1)
4d3e9548 55 Tloc=latin1 ;;
92d0a6a6 56 cp1047)
4d3e9548 57 Tloc=cp1047 ;;
92d0a6a6 58 *)
4d3e9548
JL
59 Tloc=ascii ;;
60 esac ;;
61 esac ;;
92d0a6a6 62esac
92d0a6a6
JR
63
64# `for i; do' doesn't work with some versions of sh
65
4d3e9548
JL
66Topt=
67opts=
92d0a6a6
JR
68for i
69 do
70 case $1 in
71 -c)
72 opts="$opts -P-c" ;;
73 -h)
74 opts="$opts -P-h" ;;
75 -[eq] | -s*)
76 # ignore these options
77 ;;
4d3e9548 78 -[dMmrnoTwW])
92d0a6a6
JR
79 echo "$prog: option $1 requires an argument" >&2
80 exit 1 ;;
4d3e9548 81 -[iptSUC] | -[dMmrnowW]*)
92d0a6a6 82 opts="$opts $1" ;;
92d0a6a6 83 -T*)
4d3e9548 84 Topt=$1 ;;
92d0a6a6
JR
85 -u*)
86 # Solaris 2.2 through at least Solaris 9 `man' invokes
87 # `nroff -u0 ... | col -x'. Ignore the -u0,
88 # since `less' and `more' can use the emboldening info.
89 # However, disable SGR, since Solaris `col' mishandles it.
90 opts="$opts -P-c" ;;
91 -v | --version)
92 echo "GNU nroff (groff) version @VERSION@"
93 exit 0 ;;
94 --help)
465b256c 95 echo "usage: nroff [-CchipStUv] [-dCS] [-MDIR] [-mNAME] [-nNUM] [-oLIST]"
4d3e9548 96 echo " [-rCN] [-Tname] [-WNAME] [-wNAME] [FILE...]"
92d0a6a6
JR
97 exit 0 ;;
98 --)
99 shift
100 break ;;
101 -)
102 break ;;
103 -*)
104 echo "$prog: invalid option $1" >&2
105 exit 1 ;;
106 *)
107 break ;;
108 esac
109 shift
110done
111
4d3e9548
JL
112if test "x$Topt" != x ; then
113 T=$Topt
114else
115 if test "x$Tenv" != x ; then
116 T=-T$Tenv
117 fi
118fi
119
120case $T in
121 -Tascii | -Tlatin1 | -Tutf8 | -Tcp1047)
122 ;;
123 *)
124 # ignore other devices and use locale fallback
125 T=-T$Tloc ;;
126esac
127
92d0a6a6
JR
128# Set up the `GROFF_BIN_PATH' variable
129# to be exported in the current `GROFF_RUNTIME' environment.
130
131@GROFF_BIN_PATH_SETUP@
132export GROFF_BIN_PATH
133
4d3e9548 134# Load nroff-style character definitions too.
92d0a6a6
JR
135
136PATH="$GROFF_RUNTIME$PATH" groff -mtty-char $T $opts ${1+"$@"}
137
138# eof