summaryrefslogtreecommitdiff
path: root/src/roff/nroff/nroff.sh
blob: 2e2490540d380c506a2ac9b625f54eeec649c0b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#! /bin/sh
# Emulate nroff with groff.
#
# Copyright (C) 1992, 1993, 1994, 1999, 2000, 2001, 2002, 2003,
#               2004, 2005, 2007
#   Free Software Foundation, Inc.
#
# Written by James Clark, maintained by Werner Lemberg.

# This file is of `groff'.

# `groff' is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License (GPL) as published
# by the Free Software Foundation; either version 2, or (at your
# option) any later version.

# `groff' is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with `groff'; see the files COPYING and LICENSE in the top
# directory of the `groff' source.  If not, write to the Free Software
# Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301,
# USA.

prog="$0"

# Default device.

# Check the GROFF_TYPESETTER environment variable.
Tenv=$GROFF_TYPESETTER

# Try the `locale charmap' command first because it is most reliable.
# On systems where it doesn't exist, look at the environment variables.
case "`exec 2>/dev/null ; locale charmap`" in
  UTF-8)
    Tloc=utf8 ;;
  ISO-8859-1 | ISO-8859-15)
    Tloc=latin1 ;;
  IBM-1047)
    Tloc=cp1047 ;;
  *)
    case "${LC_ALL-${LC_CTYPE-${LANG}}}" in
      *.UTF-8)
        Tloc=utf8 ;;
      iso_8859_1 | *.ISO-8859-1 | *.ISO8859-1 | \
      iso_8859_15 | *.ISO-8859-15 | *.ISO8859-15)
        Tloc=latin1 ;;
      *.IBM-1047)
        Tloc=cp1047 ;;
      *)
        case "$LESSCHARSET" in
          utf-8)
            Tloc=utf8 ;;
          latin1)
            Tloc=latin1 ;;
          cp1047)
            Tloc=cp1047 ;;
          *)
            Tloc=ascii ;;
        esac ;;
    esac ;;
esac

# `for i; do' doesn't work with some versions of sh

Topt=
opts=
for i
  do
  case $1 in
    -c)
      opts="$opts -P-c" ;;
    -h)
      opts="$opts -P-h" ;;
    -[eq] | -s*)
      # ignore these options
      ;;
    -[dMmrnoTwW])
      echo "$prog: option $1 requires an argument" >&2
      exit 1 ;;
    -[iptSUC] | -[dMmrnowW]*)
      opts="$opts $1" ;;
    -T*)
      Topt=$1 ;;
    -u*)
      # Solaris 2.2 through at least Solaris 9 `man' invokes
      # `nroff -u0 ... | col -x'.  Ignore the -u0,
      # since `less' and `more' can use the emboldening info.
      # However, disable SGR, since Solaris `col' mishandles it.
      opts="$opts -P-c" ;;
    -v | --version)
      echo "GNU nroff (groff) version @VERSION@"
      exit 0 ;;
    --help)
      echo "usage: nroff [-CchipStUv] [-dCS] [-MDIR] [-mNAME] [-nNUM] [-oLIST]"
      echo "             [-rCN] [-Tname] [-WNAME] [-wNAME] [FILE...]"
      exit 0 ;;
    --)
      shift
      break ;;
    -)
      break ;;
    -*)
      echo "$prog: invalid option $1" >&2
      exit 1 ;;
    *)
      break ;;
  esac
  shift
done

if test "x$Topt" != x ; then
  T=$Topt
else
  if test "x$Tenv" != x ; then
    T=-T$Tenv
  fi
fi

case $T in
  -Tascii | -Tlatin1 | -Tutf8 | -Tcp1047)
    ;;
  *)
    # ignore other devices and use locale fallback
    T=-T$Tloc ;;
esac

# Set up the `GROFF_BIN_PATH' variable
# to be exported in the current `GROFF_RUNTIME' environment.

@GROFF_BIN_PATH_SETUP@
export GROFF_BIN_PATH

# Load nroff-style character definitions too.

PATH="$GROFF_RUNTIME$PATH" groff -mtty-char $T $opts ${1+"$@"}

# eof