carp: add carp_group_demote_adj()
[dragonfly.git] / contrib / groff / src / roff / nroff / nroff.sh
1 #! /bin/sh
2 # Emulate nroff with groff.
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/>.
24
25 prog="$0"
26
27 # Default device.
28
29 # Check the GROFF_TYPESETTER environment variable.
30 Tenv=$GROFF_TYPESETTER
31
32 # Try the `locale charmap' command first because it is most reliable.
33 # On systems where it doesn't exist, look at the environment variables.
34 case "`exec 2>/dev/null ; locale charmap`" in
35   UTF-8)
36     Tloc=utf8 ;;
37   ISO-8859-1 | ISO-8859-15)
38     Tloc=latin1 ;;
39   IBM-1047)
40     Tloc=cp1047 ;;
41   *)
42     case "${LC_ALL-${LC_CTYPE-${LANG}}}" in
43       *.UTF-8)
44         Tloc=utf8 ;;
45       iso_8859_1 | *.ISO-8859-1 | *.ISO8859-1 | \
46       iso_8859_15 | *.ISO-8859-15 | *.ISO8859-15)
47         Tloc=latin1 ;;
48       *.IBM-1047)
49         Tloc=cp1047 ;;
50       *)
51         case "$LESSCHARSET" in
52           utf-8)
53             Tloc=utf8 ;;
54           latin1)
55             Tloc=latin1 ;;
56           cp1047)
57             Tloc=cp1047 ;;
58           *)
59             Tloc=ascii ;;
60         esac ;;
61     esac ;;
62 esac
63
64 # `for i; do' doesn't work with some versions of sh
65
66 Topt=
67 opts=
68 for 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       ;;
78     -[dMmrnoTwW])
79       echo "$prog: option $1 requires an argument" >&2
80       exit 1 ;;
81     -[iptSUC] | -[dMmrnowW]*)
82       opts="$opts $1" ;;
83     -T*)
84       Topt=$1 ;;
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)
95       echo "usage: nroff [-CchipStUv] [-dCS] [-MDIR] [-mNAME] [-nNUM] [-oLIST]"
96       echo "             [-rCN] [-Tname] [-WNAME] [-wNAME] [FILE...]"
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
110 done
111
112 if test "x$Topt" != x ; then
113   T=$Topt
114 else
115   if test "x$Tenv" != x ; then
116     T=-T$Tenv
117   fi
118 fi
119
120 case $T in
121   -Tascii | -Tlatin1 | -Tutf8 | -Tcp1047)
122     ;;
123   *)
124     # ignore other devices and use locale fallback
125     T=-T$Tloc ;;
126 esac
127
128 # Set up the `GROFF_BIN_PATH' variable
129 # to be exported in the current `GROFF_RUNTIME' environment.
130
131 @GROFF_BIN_PATH_SETUP@
132 export GROFF_BIN_PATH
133
134 # Load nroff-style character definitions too.
135
136 PATH="$GROFF_RUNTIME$PATH" groff -mtty-char $T $opts ${1+"$@"}
137
138 # eof