summaryrefslogtreecommitdiffstats
path: root/nroff
blob: 49a71bca41916312a3124e859bc5a258512fa573 (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
142
143
144
145
146
147
#!/bin/bash
# Emulate nroff with groff.

prog="$0"
charset_in=iso-8859-1
charset_out=`locale charmap 2>/dev/null`
opts="-mtty-char -Tutf8"

# Default device.
# First try the "locale charmap" command, because it's most reliable.
# On systems where it doesn't exist, look at the environment variables.
case "`locale charmap 2>/dev/null`" in
  UTF-8)
    T=-Tutf8 ;;
  ISO-8859-1)
    T=-Tlatin1 ;;
  IBM-1047)
    T=-Tcp1047 ;;
  EUC-JP)
    T=-Tnippon ;;
  EUC-KR)
    T=-Tkorean ;;
  *)
	case "${LC_ALL-${LC_CTYPE-${LANG}}}" in
      *.UTF-8)
        T=-Tutf8 ;;
      iso_8859_1 | *.ISO-8859-1)
        T=-Tlatin1 ;;
      *.IBM-1047)
        T=-Tcp1047 ;;
      ja_JP.ujis | ja_JP.eucJP)
    T=-Tnippon ;;
      ko_KR.eucKR)
        T=-Tkorean ;;
      *)
        case "$LESSCHARSET" in
          utf-8)
            T=-Tutf8 ;;
          latin1)
            T=-Tlatin1 ;;
          cp1047)
            T=-Tcp1047 ;;
          japanese)
        T=-Tnippon ;;
          ko)
            T=-Tkorean ;;
          *)
            T=-Tascii8 ;;
		esac ;;
    esac ;;
esac


for i
do
  case $1 in
    -c)
      opts="$opts -P-c" ;;
    -h)
      opts="$opts -P-h" ;;
    -[eq] | -s*)
      # ignore these options
      ;;
    -[mrnoT])
      echo $"option $1 requires an argument" >&2
      exit 1 ;;
    -[iptSUC] | -[mrno]*)
      opts="$opts $1" ;;
    -Tascii | -Tlatin1 | -Tutf8 | -Tcp1047 | -Tascii8 | -Tnippon | -Tkorean)
      opts=
      T=$1 ;;
    -T*)
      # ignore other devices
      ;;
    -v | --version)
      echo $"GNU nroff (groff) with Red Hat i18n/l10n support"
      exit 0 ;;
    --legacy)
      shift
      charset_in=$1 ;;
    --help)
      echo $"usage: $prog [-cChipt] [-mNAME] [-nNUM] [--legacy CHARSET] [-oLIST] [-rCN] [FILE...]"
      exit 0 ;;
    --)
      shift
      break ;;
    -)
      break ;;
    -*)
      echo $"$prog: invalid option $1" >&2
      exit 1 ;;
    *)
      break ;;
  esac
  shift
done

if TMPFILE=$(mktemp /tmp/man.XXXXXX 2>/dev/null); then
  trap "rm -f $TMPFILE" 0 1 2 3 15
  cat ${1+"$@"} >| $TMPFILE
else
  buf=$(cat ${1+"$@"})
  TMPFILE=buf
fi

if [ $TMPFILE = buf ]; then
  echo -n "$buf" | iconv -f utf-8 -t utf-8 &>/dev/null && charset_in=utf-8
else
  iconv -f utf-8 -t utf-8 $TMPFILE &>/dev/null && charset_in=utf-8
fi

if [ $charset_in != utf-8 ]; then
  echo XXX
  echo XXX $"WARNING: old character encoding and/or character set"
  echo XXX
fi

# en_US is chosen arbitrarily; any UTF-8 locale should work
export LC_ALL=en_US.UTF-8

# This shell script is intended for use with man, so warnings are
# probably not wanted.  Also load nroff-style character definitions.

if [ $charset_in = utf-8 -a $charset_out = UTF-8 ]; then
  if [ $TMPFILE = buf ]; then
    echo -n "$buf" | /usr/bin/groff $opts 2>/dev/null
  else
    exec < $TMPFILE
    rm -f $TMPFILE
    exec /usr/bin/groff $opts 2>/dev/null
  fi
else
  if [ $TMPFILE = buf ]; then
    echo -n "$buf" | \
      /usr/bin/iconv -f $charset_in -t utf-8 | \
      /usr/bin/groff $opts 2>/dev/null | \
      /usr/bin/iconv -f utf-8 -t ${charset_out}//translit
  else
    /usr/bin/iconv -f $charset_in -t utf-8 $TMPFILE | \
    /usr/bin/groff $opts 2>/dev/null | \
    /usr/bin/iconv -f utf-8 -t ${charset_out}//translit

    rm -f $TMPFILE
  fi
fi
 
# eof