* src/roff/nroff/nroff.man: Document option `-M'.
[s-roff.git] / src / roff / nroff / nroff.sh
blob6eac45bf7def5197a51017c748c86e318067f6b4
1 #!/bin/sh
2 # Emulate nroff with groff.
4 prog="$0"
5 # Default device.
6 # First try the "locale charmap" command, because it's most reliable.
7 # On systems where it doesn't exist, look at the environment variables.
8 case "`exec 2>/dev/null ; locale charmap`" in
9 UTF-8)
10 T=-Tutf8 ;;
11 ISO-8859-1)
12 T=-Tlatin1 ;;
13 IBM-1047)
14 T=-Tcp1047 ;;
16 case "${LC_ALL-${LC_CTYPE-${LANG}}}" in
17 *.UTF-8)
18 T=-Tutf8 ;;
19 iso_8859_1 | *.ISO-8859-1 | *.ISO8859-1)
20 T=-Tlatin1 ;;
21 *.IBM-1047)
22 T=-Tcp1047 ;;
24 case "$LESSCHARSET" in
25 utf-8)
26 T=-Tutf8 ;;
27 latin1)
28 T=-Tlatin1 ;;
29 cp1047)
30 T=-Tcp1047 ;;
32 T=-Tascii ;;
33 esac ;;
34 esac ;;
35 esac
36 opts=
38 # `for i; do' doesn't work with some versions of sh
40 for i
42 case $1 in
43 -c)
44 opts="$opts -P-c" ;;
45 -h)
46 opts="$opts -P-h" ;;
47 -[eq] | -s*)
48 # ignore these options
50 -[dMmrnoT])
51 echo "$prog: option $1 requires an argument" >&2
52 exit 1 ;;
53 -[iptSUC] | -[dMmrno]*)
54 opts="$opts $1" ;;
55 -Tascii | -Tlatin1 | -Tutf8 | -Tcp1047)
56 T=$1 ;;
57 -T*)
58 # ignore other devices
60 -u*)
61 # Solaris 2.2 through at least Solaris 9 `man' invokes
62 # `nroff -u0 ... | col -x'. Ignore the -u0,
63 # since `less' and `more' can use the emboldening info.
64 # However, disable SGR, since Solaris `col' mishandles it.
65 opts="$opts -P-c" ;;
66 -v | --version)
67 echo "GNU nroff (groff) version @VERSION@"
68 exit 0 ;;
69 --help)
70 echo "usage: nroff [-CchipStUv] [-dCS] [-MDIR] [-mNAME] [-nNUM] [-oLIST]"
71 echo " [-rCN] [-Tname] [FILE...]"
72 exit 0 ;;
73 --)
74 shift
75 break ;;
77 break ;;
78 -*)
79 echo "$prog: invalid option $1" >&2
80 exit 1 ;;
82 break ;;
83 esac
84 shift
85 done
87 # Set up the `GROFF_BIN_PATH' variable
88 # to be exported in the current `GROFF_RUNTIME' environment.
90 @GROFF_BIN_PATH_SETUP@
91 export GROFF_BIN_PATH
93 # This shell script is intended for use with man, so warnings are
94 # probably not wanted. Also load nroff-style character definitions.
96 PATH="$GROFF_RUNTIME$PATH" groff -mtty-char $T $opts ${1+"$@"}
98 # eof