tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: libcurses widechar fixes for review

Hi James - said:
> Would you be willing to answer a few questions from a guy who lives
> in the "C" locale all the time?

Sure, but be aware that my understanding of the matter is limited
too -- that's the reason I posted this patch for review.
The i18n and wide character support in NetBSD is mostly driven
by japanese developers. I hope to get some comments from there.
(I wouldn't know eg. how to get characters which take the double
width of a plain one.)

> I want the library to honor the
> client's locale.  I think the best way to do that is to call
> nl_langinfo(3).

Yes, this is recommended rather than parsing setlocale() output
or the environment.

> AUIU the user sets the environment strings e.g. LANG and LC_ALL.  Then the
> application calls setlocale(3).

And that's the difference. For a new library, you can just
require that the caller initializes the locale. State it in the
documentation, and be done. ncurses does so.
curses historically didn't have this requirement, and can't
expect applications to have called setlocale() before.

> AFAIK there's no way to know whether or not setclocale(3) was ever called,

If setlocale(LC_x, NULL) returns something different from "C",
one can be sure that someone has called it before. If it returns
"C", it might have been called before or not.
My optimistic assumption is that it doesn't hurt if it is
called a second time in this case because this leads to the
same result.
One can imagine cases where an application didn't call setlocale()
by purpose, or called it with (LC_CTYPE, "C"), to deliberately stay
away from the environment settings. Well, possible, but somewhat
unlikely for an application using curses.
I'm not 100% happy with this solution, but I don't have a
better idea either. (One could set and reset it in each call
which uses nl_langinfo() or any of the wc*() functions, but
that would be heavy. And opens questions about thread or signal
safety, and what else.)

best regards

Forschungszentrum Juelich GmbH
52425 Juelich
Sitz der Gesellschaft: Juelich
Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
Vorsitzende des Aufsichtsrats: MinDir'in Baerbel Brumme-Bothe
Geschaeftsfuehrung: Prof. Dr. Achim Bachem (Vorsitzender),
Dr. Ulrich Krafft (stellv. Vorsitzender), Prof. Dr.-Ing. Harald Bolt,
Prof. Dr. Sebastian M. Schmidt

Home | Main Index | Thread Index | Old Index