Copyright 2017
[s-roff.git] / src / nroff / nroff.sh.in
blobcda37d77a22c721f4dbb8967318eff69c77e4610
1 #!/bin/sh
2 #@ Emulate nroff with @L_ROFF@.
4 # Copyright (c) 2014 - 2017 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
6 # Copyright (C) 1992 - 1994, 1999 - 2005, 2007
7 # Free Software Foundation, Inc.
9 # Written by James Clark, maintained by Werner Lemberg.
11 # `groff' is free software; you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License (GPL) as published
13 # by the Free Software Foundation; either version 2, or (at your
14 # option) any later version.
16 # `groff' is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 # General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with `groff'; see the files COPYING and LICENSE in the top
23 # directory of the `groff' source. If not, write to the Free Software
24 # Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301,
25 # USA.
27 prog="$0"
29 # Default device.
30 # Check the @U_ROFF@_TYPESETTER environment variable.
31 Tenv="${@U_ROFF@_TYPESETTER}"
33 # Try the `locale charmap' command first because it is most reliable.
34 # On systems where it doesn't exist, look at the environment variables.
35 case "`exec 2>/dev/null ; locale charmap`" in
36 UTF-8)
37 Tloc=utf8 ;;
38 ISO-8859-1 | ISO-8859-15)
39 Tloc=latin1 ;;
40 IBM-1047)
41 Tloc=cp1047 ;;
43 case "${LC_ALL-${LC_CTYPE-${LANG}}}" in
44 *.UTF-8)
45 Tloc=utf8 ;;
46 iso_8859_1 | *.ISO-8859-1 | *.ISO8859-1 | \
47 iso_8859_15 | *.ISO-8859-15 | *.ISO8859-15)
48 Tloc=latin1 ;;
49 *.IBM-1047)
50 Tloc=cp1047 ;;
52 case "$LESSCHARSET" in
53 utf-8)
54 Tloc=utf8 ;;
55 latin1)
56 Tloc=latin1 ;;
57 cp1047)
58 Tloc=cp1047 ;;
60 Tloc=ascii ;;
61 esac ;;
62 esac ;;
63 esac
65 # `for i; do' doesn't work with some versions of sh
67 Topt=
68 opts=
69 for i
71 case $1 in
72 -c)
73 opts="$opts -P-c" ;;
74 -h)
75 opts="$opts -P-h" ;;
76 -[eq] | -s*)
77 # ignore these options
79 -[dMmrnoTwW])
80 echo "$prog: option $1 requires an argument" >&2
81 exit 1 ;;
82 -[iptSUC] | -[dMmrnowW]*)
83 opts="$opts $1" ;;
84 -T*)
85 Topt=$1 ;;
86 -u*)
87 # Solaris 2.2 through at least Solaris 9 `man' invokes
88 # `nroff -u0 ... | col -x'. Ignore the -u0,
89 # since `less' and `more' can use the emboldening info.
90 # However, disable SGR, since Solaris `col' mishandles it.
91 opts="$opts -P-c" ;;
92 -v | --version)
93 echo "@L_NROFF@ (@T_ROFF@) v@VERSION@"
94 exit 0 ;;
95 --help)
96 echo "Synopsis: @L_NROFF@ [-CchipStUv] [-dCS] [-MDIR] [-mNAME] [-nNUM]"
97 echo " [-oLIST] [-rCN] [-Tname] [-WNAME] [-wNAME] [FILE...]"
98 exit 0 ;;
99 --)
100 shift
101 break ;;
103 break ;;
105 echo "$prog: invalid option $1" >&2
106 exit 1 ;;
108 break ;;
109 esac
110 shift
111 done
113 if test "x$Topt" != x ; then
114 T=$Topt
115 else
116 if test "x$Tenv" != x ; then
117 T=-T$Tenv
121 case $T in
122 -Tascii | -Tlatin1 | -Tutf8 | -Tcp1047)
125 # ignore other devices and use locale fallback
126 T=-T$Tloc ;;
127 esac
129 # Set up the `@U_ROFF@_BIN_PATH' variable
130 # to be exported in the current `@U_ROFF@_RUNTIME' environment.
131 @U_ROFF_BIN_PATH_SETUP@
132 export @U_ROFF@_BIN_PATH
134 # Load nroff-style character definitions too.
136 PATH="${@U_ROFF@_RUNTIME}${PATH}" @L_ROFF@ -mtty-char ${T} $opts ${1+"${@}"}
138 # s-sh-mode