From owner-svn-src-all@FreeBSD.ORG Sat Apr 2 05:01:10 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3C7DD1065672; Sat, 2 Apr 2011 05:01:10 +0000 (UTC) (envelope-from gordon@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2D97F8FC08; Sat, 2 Apr 2011 05:01:10 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p3251Aog070948; Sat, 2 Apr 2011 05:01:10 GMT (envelope-from gordon@svn.freebsd.org) Received: (from gordon@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p3251AEL070946; Sat, 2 Apr 2011 05:01:10 GMT (envelope-from gordon@svn.freebsd.org) Message-Id: <201104020501.p3251AEL070946@svn.freebsd.org> From: Gordon Tetlow Date: Sat, 2 Apr 2011 05:01:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r220261 - head/usr.bin/man X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Apr 2011 05:01:10 -0000 Author: gordon Date: Sat Apr 2 05:01:09 2011 New Revision: 220261 URL: http://svn.freebsd.org/changeset/base/220261 Log: Overhaul locale handling. Use locale(1) to determine the locale instead of trying to hand roll it. Correctly construct groff call based on charset and locale independently, not the mix between the two. Submitted by: uqs@ Modified: head/usr.bin/man/man.sh Modified: head/usr.bin/man/man.sh ============================================================================== --- head/usr.bin/man/man.sh Sat Apr 2 03:48:15 2011 (r220260) +++ head/usr.bin/man/man.sh Sat Apr 2 05:01:09 2011 (r220261) @@ -312,11 +312,10 @@ man_display_page() { # device flag (-T) we have to pass to eqn(1) and groff(1). Then, # setup the pipeline of commands based on the user's request. - # Apparently the locale flags are switched on where the manpage is - # found not just the locale env variables. - nroff_dev="ascii" - case "X${use_locale}X${manpage}" in - XyesX*/${man_lang}*${man_charset}/*) + # If the manpage is from a particular charset, we need to setup nroff + # to properly output for the correct device. + case "${manpage}" in + *.${man_charset}/*) # I don't pretend to know this; I'm just copying from the # previous version of man(1). case "$man_charset" in @@ -327,9 +326,20 @@ man_display_page() { *) nroff_dev="ascii" ;; esac - NROFF="$NROFF -T$nroff_dev -dlocale=$man_lang.$man_charset" + NROFF="$NROFF -T$nroff_dev" EQN="$EQN -T$nroff_dev" + # Iff the manpage is from the locale and not just the charset, + # then we need to define the locale string. + case "${manpage}" in + */${man_lang}_${man_country}.${man_charset}/*) + NROFF="$NROFF -dlocale=$man_lang.$man_charset" + ;; + */${man_lang}.${man_charset}/*) + NROFF="$NROFF -dlocale=$man_lang.$man_charset" + ;; + esac + # Allow language specific calls to override the default # set of utilities. l=$(echo $man_lang | tr [:lower:] [:upper:]) @@ -557,28 +567,38 @@ man_setup() { # Usage: man_setup_locale # Setup necessary locale variables. man_setup_locale() { + local lang_cc + + locpaths='.' + man_charset='US-ASCII' + # Setup locale information. if [ -n "$oflag" ]; then - decho "Using non-localized manpages" - unset use_locale - elif [ -n "$LC_ALL" ]; then - parse_locale "$LC_ALL" - elif [ -n "$LC_CTYPE" ]; then - parse_locale "$LC_CTYPE" - elif [ -n "$LANG" ]; then - parse_locale "$LANG" - fi - - if [ -n "$use_locale" ]; then - locpaths="${man_lang}_${man_country}.${man_charset}" - locpaths="$locpaths:$man_lang.$man_charset" - if [ "$man_lang" != "en" ]; then - locpaths="$locpaths:en.$man_charset" - fi - locpaths="$locpaths:." + decho 'Using non-localized manpages' else - locpaths="." + # Use the locale tool to give us the proper LC_CTYPE + eval $( $LOCALE ) + + case "$LC_CTYPE" in + C) ;; + POSIX) ;; + [a-z][a-z]_[A-Z][A-Z]\.*) + lang_cc="${LC_CTYPE%.*}" + man_lang="${LC_CTYPE%_*}" + man_country="${lang_cc#*_}" + man_charset="${LC_CTYPE#*.}" + locpaths="$LC_CTYPE" + locpaths="$locpaths:$man_lang.$man_charset" + if [ "$man_lang" != "en" ]; then + locpaths="$locpaths:en.$man_charset" + fi + locpaths="$locpaths:." + ;; + *) echo 'Unknown locale, assuming C' >&2 + ;; + esac fi + decho "Using locale paths: $locpaths" } @@ -660,28 +680,6 @@ parse_file() { done < "$file" } -# Usage: parse_locale localestring -# Setup locale variables for proper parsing. -parse_locale() { - local lang_cc - - case "$1" in - C) ;; - POSIX) ;; - [a-z][a-z]_[A-Z][A-Z]\.*) lang_cc="${1%.*}" - man_lang="${1%_*}" - man_country="${lang_cc#*_}" - man_charset="${1#*.}" - use_locale=yes - return 0 - ;; - *) echo 'Unknown locale, assuming C' >&2 - ;; - esac - - unset use_locale -} - # Usage: search_path # Traverse $PATH looking for manpaths. search_path() { @@ -893,6 +891,7 @@ do_whatis() { EQN=/usr/bin/eqn COL=/usr/bin/col +LOCALE=/usr/bin/locale NROFF='/usr/bin/groff -S -Wall -mtty-char -man' PIC=/usr/bin/pic SYSCTL=/sbin/sysctl