ACC SHELL

Path : /usr/bin/
File Upload :
Current File : //usr/bin/nroff

#!/bin/sh
# 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 "`locale charmap 2>/dev/null`" 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

for i
  do
  case $1 in
    -c)
      opts="$opts -P-c" ;;
    -h)
      opts="$opts -P-h" ;;
    -[eq] | -s*)
      # ignore these options
      ;;
    -[mrnoT])
      echo "$prog: option $1 requires an argument" >&2
      exit 1 ;;
    -[iptSUC] | -[mrno]*)
      opts="$opts $1" ;;
    -Tascii | -Tlatin1 | -Tutf8 | -Tcp1047 | -Tascii8 | -Tnippon)
      T=$1 ;;
    -T*)
      # ignore other devices
      ;;
    -u*)
      # Solaris 2.2 `man' uses -u0; ignore it,
      # since `less' and `more' can use the emboldening info.
      ;;
    -v | --version)
      echo "GNU nroff (groff) version 1.18.1"
      exit 0 ;;
    --help)
      echo "usage: nroff [-cChipt] [-mNAME] [-nNUM] [-oLIST] [-rCN] [-Tname] [FILE...]"
      exit 0 ;;
    --)
      shift
      break ;;
    -)
      break ;;
    -*)
      echo "$prog: invalid option $1" >&2
      exit 1 ;;
    *)
      break ;;
  esac
  shift
done

# special hacks to display Japanese, Chinese, ...man pages correctly in UTF-8 locale:

guess_legacy_encoding () {
    # Guess the legacy encoding used by the language/country
    # found in the current LC_CTYPE value.

    # First determine the LC_CTYPE locale category setting
    ctype=${LC_ALL-${LC_CTYPE-${LANG-en_US}}}

    case $ctype in
	  zh_TW*)
             LEGACY_ENCODING=Big5
	     ;;
  	  zh_HK*)
             LEGACY_ENCODING=Big5HKSCS
	     ;;
	  zh*)
             LEGACY_ENCODING=GB18030
	     ;;
	  ja*)
             LEGACY_ENCODING=EUC-JP
	     ;;
	  ko*)
             LEGACY_ENCODING=EUC-KR
	     ;;
	  ru*)
             LEGACY_ENCODING=KOI8-R
	     ;;
	  uk*)
             LEGACY_ENCODING=KOI8-U
	     ;;
	  pl*|hr*|hu*|cs*|sk*|sl*)
             LEGACY_ENCODING=ISO-8859-2
	     ;;
	  eo*|mt*)
             LEGACY_ENCODING=ISO-8859-3
	     ;;
	  el*)
             LEGACY_ENCODING=ISO-8859-7
	     ;;
	  he*)
             LEGACY_ENCODING=ISO-8859-8
	     ;;
	  tr*)
             LEGACY_ENCODING=ISO-8859-9
	     ;;
	  th*)
             LEGACY_ENCODING=TIS-620      # or ISO-8859-11
	     ;;
	  lt*)
             LEGACY_ENCODING=ISO-8859-13
	     ;;
	  cy*)
             LEGACY_ENCODING=ISO-8859-14
	     ;;
	  ro*)
             LEGACY_ENCODING=ISO-8859-14  # or ISO-8859-16
	     ;;
	  am*|vi*)
             LEGACY_ENCODING=UTF-8
	     ;;
          *)
             LEGACY_ENCODING=ISO-8859-1
             ;;
    esac
}

guess_legacy_encoding;

TMPDIR=`mktemp -d /tmp/nroff.XXXXXX`
if [ $? -ne 0 ]; then
        echo "$0: Can't create temp directory, exiting..."
        exit 1
fi
trap "exec rm -rf $TMPDIR" EXIT SIGHUP SIGINT SIGPIPE SIGTERM SIGIO

# parse groff options to find out whether a file was given as argument or whether the
# input is read from stdin:
OLDARGS=""
TEMP=$(getopt --options  "abcCd:eEf:F:gGhiI:lL:m:M:n:No:pP:r:RsStT:UvVw:W:XzZ" --longoptions help,version -- ${1+"$@"})
eval set -- "$TEMP"
while true ; do
    case "$1" in
	--)
	    if [ -n "$2" ] ; then
		INPUTFILE="$2"
		shift 2
	    else
		INPUTFILE=""
		shift 1
	    fi
	    break
	    ;;
	*)
	    OLDARGS="$OLDARGS $1"
	    echo $1
	    shift 1
	    ;;
    esac
done
eval set -- "$OLDARGS"

if [ -n "$INPUTFILE" ] ; then
    # input comes from a file
    cat "$INPUTFILE" > $TMPDIR/input
else
    # input comes from stdin
    cat > $TMPDIR/input
fi

#iconv -s -c -f utf-8 -t utf-8 < $TMPDIR/input > /dev/null
#if [ $? -eq 0 ]; then
#    iconv -s -c -f utf-8 -t $LEGACY_ENCODING < $TMPDIR/input > $TMPDIR/input.new
#    mv $TMPDIR/input.new $TMPDIR/input
#fi

getlang () {
    if [ -n "$LANGUAGE" ]; then
	echo $LANGUAGE
    elif [ -n "$LC_ALL" ]; then
	echo $LC_ALL
    elif [ -n "$LC_MESSAGES" ]; then
	echo $LC_MESSAGES
    else
	echo $LANG
    fi
}

ICONV="cat"
case "`locale charmap 2>/dev/null`" in
    UTF-8)
    case `getlang` in
        ja*)
        # Japanese man page in UTF-8 locale, special case!
        # force the device 'nippon' to run groff in ja_JP.eucJP locale
        # and convert the result to UTF-8 using iconv:
        T=-Tnippon
        export LC_ALL=ja_JP.eucJP
        ICONV="iconv -f EUC-JP -t UTF-8"
        ;;
        zh_TW*)
        T=-Tnippon
        export LC_ALL=zh_TW.Big5
        ICONV="iconv -f Big5 -t UTF-8"
        ;;
        zh_HK*)
        T=-Tnippon
        export LC_ALL=zh_HK.Big5HKSCS
        ICONV="iconv -f Big5HKSCS -t UTF-8"
        ;;
        zh*)
        T=-Tnippon
        export LC_ALL=zh_CN.GB18030
        ICONV="iconv -f GB18030 -t UTF-8"
        ;;
        ko*)
        T=-Tlatin1
        export LC_ALL=ko_KR.EUC-KR
        # See https://bugzilla.novell.com/show_bug.cgi?id=470921
        # for the reason why the "-c" is needed and
        # why a conversion from ISO-8859-1 instead of EUC-KR to
        # UTF-8 may be needed if an English man-page is displayed:
        ICONV="iconv -c -f EUC-KR -t UTF-8"
        iconv -s -f ASCII -t UTF-8 < $TMPDIR/input > /dev/null
        if [ $? -eq 0 ]; then
            ICONV="iconv -f ISO-8859-1 -t UTF-8"
        fi
        ;;
        # make 'man iso-8859-15' display correctly in UTF-8 locales using Euro
        ca_ES*|de_AT*|de_BE*|de_DE*|de_LU*|en_BE*|en_IE*|es_ES*|eu_ES*|fi_FI*|fr_BE*|fr_FR*|fr_LU*|ga_IE*|gl_ES*|it_IT*|nl_BE*|nl_NL*|pt_PT*|sv_FI*|wa_BE*)
        T=-Tlatin1
        export LC_ALL=de_DE@euro
        ICONV="iconv -f ISO-8859-15 -t UTF-8"
        ;;
    esac
    ;;
esac

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

: ${GROFF_BIN_PATH=/usr/bin}
export GROFF_BIN_PATH
PATH=$GROFF_BIN_PATH:$PATH groff -mtty-char $T $opts ${1+"$@"} < $TMPDIR/input | $ICONV

# eof

ACC SHELL 2018