nroff.sh revision 69631
1#!/bin/sh
2# Emulate nroff with groff.
3# $FreeBSD: head/contrib/groff/src/roff/nroff/nroff.sh 69631 2000-12-05 19:06:41Z ru $
4
5prog="$0"
6# Default device.
7# First try the "locale charmap" command, because it's most reliable.
8# On systems where it doesn't exist, look at the environment variables.
9case "`#locale charmap 2>/dev/null`" in
10  UTF-8)
11    T=-Tutf8 ;;
12  ISO-8859-1)
13    T=-Tlatin1 ;;
14  IBM-1047)
15    T=-Tcp1047 ;;
16  *)
17    case "${LC_ALL-${LC_CTYPE-${LANG}}}" in
18      *.UTF-8)
19        T=-Tutf8 ;;
20      iso_8859_1 | *.ISO-8859-1 | *.ISO_8859-1)
21        T=-Tlatin1 ;;
22      *.IBM-1047)
23        T=-Tcp1047 ;;
24      *.KOI8-R)
25        T=-Tkoi8-r ;;
26      *)
27        case "$LESSCHARSET" in
28          utf-8)
29            T=-Tutf8 ;;
30          latin1)
31            T=-Tlatin1 ;;
32          cp1047)
33            T=-Tcp1047 ;;
34          *)
35            T=-Tascii ;;
36          esac ;;
37     esac ;;
38esac
39opts=
40safer=-S
41
42# `for i; do' doesn't work with some versions of sh
43
44for i
45  do
46  case $1 in
47    -h)
48      opts="$opts -P-h" ;;
49    -[eq] | -s*)
50      # ignore these options
51      ;;
52    -[mrnoT])
53      echo "$prog: option $1 requires an argument" >&2
54      exit 1 ;;
55    -[itp] | -[mrno]*)
56      opts="$opts $1" ;;
57    -Tascii | -Tlatin1 | -Tkoi8-r | -Tutf8 | -Tcp1047)
58      T=$1 ;;
59    -T*)
60      # ignore other devices
61      ;;
62    -S)
63      # safer behaviour
64      safer=-S ;;
65    -U)
66      # unsafe behaviour
67      safer=-U ;;
68    -u*)
69      # Solaris 2.2 `man' uses -u0; ignore it,
70      # since `less' and `more' can use the emboldening info.
71      ;;
72    --)
73      shift
74      break ;;
75    -)
76      break ;;
77    -*)
78      echo "$prog: invalid option $1" >&2
79      exit 1 ;;
80    *)
81      break ;;
82  esac
83  shift
84done
85
86# This shell script is intended for use with man, so warnings are
87# probably not wanted.  Also load nroff-style character definitions.
88exec groff $safer -Wall -mtty-char $T $opts ${1+"$@"}
89