Discussion:
Some of my nanoseconds are missing....
Patrick Pinchera
2010-11-04 21:51:33 UTC
Permalink
Does anyone know if this was ever put into production code? I'd really
like to make this work in some of my scripts:

printf("%'d\n", 123000);

should print out "123,000" if LC_ALL is set to something other than "C",
say en_US.ISO8859-1.

Right now it's not. Solaris 10 10/09 prints out "123000"

Solaris 11 Express b148 prints out "123000"

The posting below from 2006 was the only entry n this subject that I
could find.

Thanks,
Pat
Re: Some of my nanoseconds are missing...
Posted: Aug 8, 2006 2:11 PM in response to: Nik Clayton
Click to reply to this thread Reply
I'm instrumenting Sendmail (as some of you are probably bored of
hearing).
...
PS: Any chance D could grow a pragma to automatically insert commas in
large numbers? It would make comparing results much easier.
There is actually already a way to do this, but unfortunately it's a bit
blocked behind a stupid bug/oversight. printf(3S) uses the quote (')
character as a format flag that tells it to insert the locale's thousands
grouping character for %i, %d, %u, %f, %F, %g, or %G. And this is actually
printf("%'d\n", 123000);
However, in order for the underlying printf to do anything with %', the
locale subsystem has to be initialized by a call to setlocale(). And I
lazily forgot to put this into dtrace(1M), in part because my locale of
choice, POSIX C, maddeningly doesn't implement the thousands separator,
and thus until that issue is fixed or worked-around, I can't use it (!)
So, if you want to fix this yourself temporarily, put this into
#include <locale.h>
setlocale(LC_NUMERIC, "");
LC_NUMERIC=en_US dtrace <args ...>
(or just have your default locale be a non-C locale, or set LC_ALL) and it
should work. We'll get this fixed, although with the POSIX locale issue
still to be resolved. If you want to see if your locale supports a
grouping
$ LC_NUMERIC=en_US locale -k thousands_sep
thousands_sep=","
$ LC_NUMERIC=C locale -k thousands_sep
thousands_sep=""
Since you're in the UK, I'm sure you've got the appropriate character
set as Her Majesty intended it to be :)
-Mike
--
Mike Shapiro, Solaris Kernel Development. blogs.sun.com/mws/
Adam Leventhal
2010-11-08 18:17:52 UTC
Permalink
Hi Patrick,

It looks like dtrace(1M) isn't invoking setlocale(3C) to elicit the printf
behavior you describe. This is a bug in DTrace.

Adam

On Thu, Nov 4, 2010 at 2:51 PM, Patrick Pinchera <
Post by Patrick Pinchera
Does anyone know if this was ever put into production code? I'd really
printf("%'d\n", 123000);
should print out "123,000" if LC_ALL is set to something other than "C",
say en_US.ISO8859-1.
Right now it's not. Solaris 10 10/09 prints out "123000"
Solaris 11 Express b148 prints out "123000"
The posting below from 2006 was the only entry n this subject that I could
find.
Thanks,
Pat
Re: Some of my nanoseconds are missing...
Posted: Aug 8, 2006 2:11 PM in response to: Nik Clayton
Click to reply to this thread Reply
I'm instrumenting Sendmail (as some of you are probably bored of
hearing).
...
PS: Any chance D could grow a pragma to automatically insert commas in
large numbers? It would make comparing results much easier.
There is actually already a way to do this, but unfortunately it's a bit
blocked behind a stupid bug/oversight. printf(3S) uses the quote (')
character as a format flag that tells it to insert the locale's thousands
grouping character for %i, %d, %u, %f, %F, %g, or %G. And this is actually
printf("%'d\n", 123000);
However, in order for the underlying printf to do anything with %', the
locale subsystem has to be initialized by a call to setlocale(). And I
lazily forgot to put this into dtrace(1M), in part because my locale of
choice, POSIX C, maddeningly doesn't implement the thousands separator,
and thus until that issue is fixed or worked-around, I can't use it (!)
So, if you want to fix this yourself temporarily, put this into
#include <locale.h>
setlocale(LC_NUMERIC, "");
LC_NUMERIC=en_US dtrace <args ...>
(or just have your default locale be a non-C locale, or set LC_ALL) and it
should work. We'll get this fixed, although with the POSIX locale issue
still to be resolved. If you want to see if your locale supports a
grouping
$ LC_NUMERIC=en_US locale -k thousands_sep
thousands_sep=","
$ LC_NUMERIC=C locale -k thousands_sep
thousands_sep=""
Since you're in the UK, I'm sure you've got the appropriate character
set as Her Majesty intended it to be :)
-Mike
--
Mike Shapiro, Solaris Kernel Development. blogs.sun.com/mws/
_______________________________________________
dtrace-discuss mailing list
--
Adam Leventhal, Delphix http://dtrace.org/blogs/ahl
Loading...