* src/roff/nroff/nroff.sh: Handle GROFF_TYPESETTER environment
[s-roff.git] / src / roff / nroff / nroff.sh
blobafd6bf906c4cb391a4a9ef97e16b8e17fedab098
1 #! /bin/sh
2 # Emulate nroff with groff.
4 # Copyright (C) 1992, 1993, 1994, 1999, 2000, 2001, 2002, 2003,
5 # 2004, 2005, 2007
6 # Free Software Foundation, Inc.
8 # Written by James Clark, maintained by Werner Lemberg.
10 # This file is of `groff'.
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 2, or (at your
15 # option) any later version.
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.
22 # You should have received a copy of the GNU General Public License
23 # along with `groff'; see the files COPYING and LICENSE in the top
24 # directory of the `groff' source. If not, write to the Free Software
25 # Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301,
26 # USA.
28 prog="$0"
30 # Default device.
32 # Check the GROFF_TYPESETTER environment variable.
33 Tenv=$GROFF_TYPESETTER
35 # Try the `locale charmap' command first because it is most reliable.
36 # On systems where it doesn't exist, look at the environment variables.
37 case "`exec 2>/dev/null ; locale charmap`" in
38 UTF-8)
39 Tloc=utf8 ;;
40 ISO-8859-1 | ISO-8859-15)
41 Tloc=latin1 ;;
42 IBM-1047)
43 Tloc=cp1047 ;;
45 case "${LC_ALL-${LC_CTYPE-${LANG}}}" in
46 *.UTF-8)
47 Tloc=utf8 ;;
48 iso_8859_1 | *.ISO-8859-1 | *.ISO8859-1 | \
49 iso_8859_15 | *.ISO-8859-15 | *.ISO8859-15)
50 Tloc=latin1 ;;
51 *.IBM-1047)
52 Tloc=cp1047 ;;
54 case "$LESSCHARSET" in
55 utf-8)
56 Tloc=utf8 ;;
57 latin1)
58 Tloc=latin1 ;;
59 cp1047)
60 Tloc=cp1047 ;;
62 Tloc=ascii ;;
63 esac ;;
64 esac ;;
65 esac
67 # `for i; do' doesn't work with some versions of sh
69 Topt=
70 opts=
71 for i
73 case $1 in
74 -c)
75 opts="$opts -P-c" ;;
76 -h)
77 opts="$opts -P-h" ;;
78 -[eq] | -s*)
79 # ignore these options
81 -[dMmrnoT])
82 echo "$prog: option $1 requires an argument" >&2
83 exit 1 ;;
84 -[iptSUC] | -[dMmrno]*)
85 opts="$opts $1" ;;
86 -T*)
87 Topt=$1 ;;
88 -u*)
89 # Solaris 2.2 through at least Solaris 9 `man' invokes
90 # `nroff -u0 ... | col -x'. Ignore the -u0,
91 # since `less' and `more' can use the emboldening info.
92 # However, disable SGR, since Solaris `col' mishandles it.
93 opts="$opts -P-c" ;;
94 -v | --version)
95 echo "GNU nroff (groff) version @VERSION@"
96 exit 0 ;;
97 --help)
98 echo "usage: nroff [-CchipStUv] [-dCS] [-MDIR] [-mNAME] [-nNUM] [-oLIST]"
99 echo " [-rCN] [-Tname] [FILE...]"
100 exit 0 ;;
102 shift
103 break ;;
105 break ;;
107 echo "$prog: invalid option $1" >&2
108 exit 1 ;;
110 break ;;
111 esac
112 shift
113 done
115 if test "x$Topt" != x ; then
116 T=$Topt
117 else
118 if test "x$Tenv" != x ; then
119 T=-T$Tenv
123 case $T in
124 -Tascii | -Tlatin1 | -Tutf8 | -Tcp1047)
127 # ignore other devices and use locale fallback
128 T=-T$Tloc ;;
129 esac
131 # Set up the `GROFF_BIN_PATH' variable
132 # to be exported in the current `GROFF_RUNTIME' environment.
134 @GROFF_BIN_PATH_SETUP@
135 export GROFF_BIN_PATH
137 # This shell script is intended for use with man, so warnings are
138 # probably not wanted. Also load nroff-style character definitions.
140 PATH="$GROFF_RUNTIME$PATH" groff -mtty-char $T $opts ${1+"$@"}
142 # eof