On Fri, Aug 19, 2016 at 09:43:22AM -0700, Kevin J. McCarthy wrote:
 
> The documentation for setlocale() says a value of "" will cause the
> locale to be modified by environment variables, so it seems like this is
> what we would want in the index, isn't it?

Yes.  But moreover, why is setlocale being called more than once, in
different ways?  It should be done in exactly two places:  when Mutt
is first initialized, and when $locale is changed.  In both cases, it
should be set by mutt by calling:

   setlocale(LC_ALL, "");

...and absolutely nothing else.  This will cause all of the bits of
the locale to be properly inherited by their respective environment
variables.  Note that ctime() does not honor locale, but strftime()
does.  This program demonstrates proper locale configuration in C:

-=-=-=-=-
$ cat timeloc.c
#include <stdio.h>
#include <time.h>
#include <locale.h>

int main(int argc, char **argv)
{
    time_t now;
    struct tm *now_tm;
    char buf[2048];
    int rc;

    setlocale(LC_ALL, "");
    time(&now);
    now_tm = localtime(&now);
    rc = strftime(buf, 2048, "%c", now_tm);
    printf("ctime says: %s", ctime(&now));
    printf("stftime() says: %s\n", buf);
    return 0;
}
-=-=-=-=-

And, to demonstrate:

$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_US.UTF-8
LC_TIME="en_US.UTF-8"
LC_COLLATE=C
LC_MONETARY=en_US.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_ALL=
$ ./timeloc
ctime says: Fri Aug 19 13:57:02 2016
stftime() says: Fri 19 Aug 2016 01:57:02 PM EDT
$ export LC_TIME=ko_KR.UTF-8
$ ./timeloc
ctime says: Fri Aug 19 13:57:06 2016
stftime() says: 2016년 08월 19일 (금) 오후 01시 57분 06초


NOTE: In this example I explicitly set LC_TIME instead of LANG or
LC_ALL to demonstrate that even if you set the individual LC_*
variables, setlocale(LC_ALL, "") is all you ever need to make sure
that your program inherits properly from the locale environment
variables.

Also, FWIW for those of you who see my second run as garbage, I've set
the TIME format to Korean, so you probably just don't have that locale
installed and/or your terminal is not configured to display CJK
characters.

-- 
Derek D. Martin    http://www.pizzashack.org/   GPG Key ID: 0xDFBEAD02
-=-=-=-=-
This message is posted from an invalid address.  Replying to it will result in
undeliverable mail due to spam prevention.  Sorry for the inconvenience.

Attachment: pgpBl7S9Y0Ve_.pgp
Description: PGP signature

Reply via email to