Subject: Re: new stdlib?
To: None <wulf@ping.net.au, netbsd-help@netbsd.org>
From: Paul Sander <paul@wakawaka.com>
List: netbsd-help
Date: 02/09/2000 09:53:18
The %m$nd format has to do with the XPG4 standard, as defined by The Open
Group (formerly X/Open and OSF, I believe). It allows the rearrangement of
the arguments with regard to localization.
An example of this usage would be localizing the display of a date. To
show a date in American format, you could use something like this:
sprintf( c_datestring, "%2$02d/%1$02d/%3$04d",
(int)tmdate.tm_mday, (int)tmdate.tm_mon+1,
(int)tmdate.tm_year+1900 );
But the European format reverses the month and day, like this:
sprintf( c_datestring, "%1$02d/%2$02d/%3$04d",
(int)tmdate.tm_mday, (int)tmdate.tm_mon+1,
(int)tmdate.tm_year+1900 );
The value of this becomes apparent when the format string itself is
read from a message catalog.
You can find details on www.opengroup.org and searching for sprintf in
"The Single Unix Specification" (which you must hunt for, and register
to read for free).
--- Forwarded mail from wulf@ping.net.au
does anyone know the following construct? It was found in anteater
which segfaults at that point.
[...]
sprintf( c_datestring, "year %1$02d, day %2$02d, month %3$04d",
(int)tmdate.tm_mday, (int)tmdate.tm_mon+1,
(int)tmdate.tm_year+1900 );
string newdate = c_datestring;
return newdate;
I've expanded the format string which is constructed earlier
in the code. I've never seen the use of a "%1$02d" format string nor have I
found any references in books and manuals. When changed to
"%02d" the program runs fine and displays the correct date format.
Is there a new stdlib with extentions of the current format string? I am
using egcs-1.1.1 and standard libraries as shipped with NetBSD-1.4.1.
--- End of forwarded message from wulf@ping.net.au