--- groff-1.19.1/src/roff/nroff/nroff.sh.nroff 2006-09-15 10:20:19.000000000 +0200 +++ groff-1.19.1/src/roff/nroff/nroff.sh 2006-09-15 10:23:16.000000000 +0200 @@ -2,43 +2,6 @@ # Emulate nroff with groff. prog="$0" -# 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 "`exec 2>/dev/null ; locale charmap`" in - UTF-8) - T=-Tutf8 ;; - ISO-8859-1) - T=-Tlatin1 ;; - IBM-1047) - T=-Tcp1047 ;; - EUC-JP) - T=-Tnippon ;; - *) - 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 ;; - *) - case "$LESSCHARSET" in - utf-8) - T=-Tutf8 ;; - latin1) - T=-Tlatin1 ;; - cp1047) - T=-Tcp1047 ;; - japanese) - T=-Tnippon ;; - *) - T=-Tascii8 ;; - esac ;; - esac ;; -esac opts= # `for i; do' doesn't work with some versions of sh @@ -58,8 +21,8 @@ exit 1 ;; -[iptSUC] | -[dmrno]*) opts="$opts $1" ;; - -Tascii | -Tlatin1 | -Tutf8 | -Tcp1047 | -Tascii8 | -Tnippon) - T=$1 ;; +# -Tascii | -Tlatin1 | -Tutf8 | -Tcp1047) +# T=$1 ;; -T*) # ignore other devices ;; @@ -90,6 +53,33 @@ shift done +# copy the man page to a temp file +TMPFILE=$(mktemp /tmp/man.XXXXXX) +trap "rm -f $TMPFILE" 0 1 2 3 15 +cat ${1+"$@"} >| ${TMPFILE} + +# test the charset encoding of the man page +if iconv -f utf-8 -t utf-8 -o /dev/null ${TMPFILE} 2>/dev/null +then + charset_in=utf-8 +else + # non utf-8 encoding + case "${LANGUAGE-${LC_CTYPE-${LANG}}}" in + cs*|hr*|hu*|pl*|ro*|sk*|sl*) charset_in=iso-8859-2 ;; + el*) charset_in=iso-8859-7 ;; + tr*) charset_in=iso-8859-9 ;; + bg*) charset_in=cp1251 ;; + ja*) charset_in=euc-jp ;; + ko*) charset_in=euc-kr ;; + ru*) charset_in=koi8-r ;; + uk*) charset_in=koi8-u ;; + zh_TW*|zh_HK*) charset_in=big5 ;; + zh_CN*|zh*) charset_in=gb2312 ;; + *) charset_in=iso-8859-1 ;; + esac +fi +charset_out=`locale charmap 2>/dev/null` + # Set up the `GROFF_BIN_PATH' variable # to be exported in the current `GROFF_RUNTIME' environment. @@ -99,6 +89,10 @@ # This shell script is intended for use with man, so warnings are # probably not wanted. Also load nroff-style character definitions. -PATH="$GROFF_RUNTIME$PATH" groff -mtty-char $T $opts ${1+"$@"} +/usr/bin/iconv -f ${charset_in} -t ${charset_out}//translit ${TMPFILE} | \ + PATH="$GROFF_RUNTIME$PATH" groff -mtty-char -Tutf8 $opts 2>/dev/null | \ + /usr/bin/iconv -f utf-8 -t ${charset_out}//translit + +rm -f ${TMPFILE} # eof