This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 2/2] ldd: Don't use Bash-only $"msgid" quoting


On 2012-11-23 15:02, Dmitry V. Levin wrote:
> On Fri, Nov 23, 2012 at 01:23:14PM -0500, P. J. McDermott wrote:
> [...]
>> Well here's a patch that makes ldd use gettext.sh if found and otherwise
>> define simple gettext and eval_gettext functions.  Though these
>> functions should probably be defined more globally for use in other
>> scripts in glibc.
>>
>> Comments/improvements?
> [...]
>> -TEXTDOMAIN=libc
>> -TEXTDOMAINDIR=@TEXTDOMAINDIR@
>> +export TEXTDOMAIN=libc
>> +export TEXTDOMAINDIR=@TEXTDOMAINDIR@
> 
> One may note that this syntax is not quite portable.  Another issue
> with exported variables is that they leak to processes being traced.

The exporting is necessary for the gettext utility.

An alternative would be a wrapper function that calls gettext like:

    TEXTDOMAIN=libc TEXTDOMAINDIR=@TEXTDOMAINDIR@ gettext "$1"

Should we do that instead?

>> +if (. 2>/dev/null gettext.sh); then
>> +  . gettext.sh
>> +else
>> +  # No internationalization available; just print the original strings.
>> +  gettext ()
>> +  {
>> +    printf '%s' "$1"
>> +  }
> 
> I suggest making this more robust by defining our default gettext()
> unconditionally and letting gettext.sh override it.

The issue with this is that gettext isn't a function defined in
gettext.sh; it's an external utility.  The shell will look for a gettext
function before searching PATH for a gettext utility.

Would something like this be better?

    if ! gettext 2>/dev/null; then
      gettext ()
      {
        #...
      }
    fi

In fact, gettext.sh is only needed for the definition of eval_gettext.

>> +  eval_gettext ()
>> +  {
> 
> Are you sure we really have to use that ugly eval_gettext?
> Wouldn't it be better to change the code to use simpler forms?
> The only affected piece in ldd is this one:

I don't disagree that it's a bit ugly, but it's similar in basic
function to the one in gettext.sh (which uses envsubst instead of sed).

>> -    echo >&2 $"ldd: option \`$1' is ambiguous"
>> +    echo >&2 "$(eval_gettext "ldd: option \`\$1' is ambiguous")"
> 
> Let's transform original
> echo >&2 $"ldd: option \`$1' is ambiguous"
> to
> printf >&2 $"ldd: option \`%s' is ambiguous\n" "$1"
> so that it could be later changed e.g. to
> printf >&2 "$(gettext "ldd: option \`%s' is ambiguous\n")" "$1"

I thought the convention with gettext in shell command language was to
use variable expansions with echo instead of format strings with printf
(also I tried to not modify translatable strings).  I'm probably wrong.

Either way, I do prefer using printf (for this reason and others).

Thanks,
-- 
P. J. McDermott
http://www.pehjota.net/
http://www.pehjota.net/contact.html


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]