xref: /csrg-svn/lib/libc/locale/setlocale.3 (revision 62933)
1*62933Sbostic.\" Copyright (c) 1993
2*62933Sbostic.\"	The Regents of the University of California.  All rights reserved.
358383Sbostic.\"
458383Sbostic.\" This code is derived from software contributed to Berkeley by
558383Sbostic.\" Donn Seeley at BSDI.
658383Sbostic.\"
758383Sbostic.\" %sccs.include.redist.roff%
858383Sbostic.\"
9*62933Sbostic.\"	@(#)setlocale.3	8.1 (Berkeley) 06/09/93
1058383Sbostic.\"
1158383Sbostic.Dd
1258383Sbostic.Dt SETLOCALE 3
1358383Sbostic.Os
1458383Sbostic.Sh NAME
1558383Sbostic.Nm setlocale ,
1658383Sbostic.Nm localeconv
1758383Sbostic.Nd natural language formatting for C
1858383Sbostic.Sh SYNOPSIS
1958383Sbostic.Fd #include <locale.h>
2058383Sbostic.Ft char *
2158383Sbostic.Fn setlocale "int category" "const char *locale"
2258383Sbostic.Ft struct lconv *
2358383Sbostic.Fn localeconv "void"
2458383Sbostic.Sh DESCRIPTION
2558383SbosticThe
2658383Sbostic.Fn setlocale
2758383Sbosticfunction sets the C library's notion
2858383Sbosticof natural language formatting style
2958383Sbosticfor particular sets of routines.
3058383SbosticEach such style is called a
3158383Sbostic.Sq locale
3258383Sbosticand is invoked using an appropriate name passed as a C string.
3358383SbosticThe
3458383Sbostic.Fn localeconv
3558383Sbosticroutine returns the current locale's parameters
3658383Sbosticfor formatting numbers.
3758383Sbostic.Pp
3858383SbosticThe
3958383Sbostic.Fn setlocale
4058383Sbosticfunction recognizes several categories of routines.
4158383SbosticThese are the categories and the sets of routines they select:
4258383Sbostic.Pp
4358383Sbostic.Bl -tag -width LC_MONETARY
4458383Sbostic.It Dv LC_ALL
4558383SbosticSet the entire locale generically.
4658383Sbostic.It Dv LC_COLLATE
4758383SbosticSet a locale for string collation routines.
4858383SbosticThis controls alphabetic ordering in
4958383Sbostic.Fn strcoll
5058383Sbosticand
5158383Sbostic.Fn strxfrm .
5258383Sbostic.It Dv LC_CTYPE
5358383SbosticSet a locale for the
5461079Sbostic.Xr ctype 3 ,
5561079Sbostic.Xr mbrune 3 ,
5661079Sbostic.Xr multibyte 3
5758383Sbosticand
5861079Sbostic.Xr rune 3
5958383Sbosticfunctions.
6058383SbosticThis controls recognition of upper and lower case,
6158383Sbosticalphabetic or non-alphabetic characters,
6261079Sbosticand so on.  The real work is done by the
6361079Sbostic.Fn setrunelocale
6461079Sbosticfunction.
6558383Sbostic.It Dv LC_MONETARY
6658383SbosticSet a locale for formatting monetary values;
6758383Sbosticthis affects the
6858383Sbostic.Fn localeconv
6958383Sbosticfunction.
7058383Sbostic.It Dv LC_NUMERIC
7158383SbosticSet a locale for formatting numbers.
7258383SbosticThis controls the formatting of decimal points
7358383Sbosticin input and output of floating point numbers
7458383Sbosticin functions such as
7558383Sbostic.Fn printf
7658383Sbosticand
7758383Sbostic.Fn scanf ,
7858383Sbosticas well as values returned by
7958383Sbostic.Fn localeconv .
8058383Sbostic.It Dv LC_TIME
8158383SbosticSet a locale for formatting dates and times using the
8258383Sbostic.Fn strftime
8358383Sbosticfunction.
8458383Sbostic.El
8558383Sbostic.Pp
8661079SbosticOnly three locales are defined by default,
8758383Sbosticthe empty string
8858383Sbostic.Li "\&""\|""
8958383Sbosticwhich denotes the native environment, and the
9058383Sbostic.Li "\&""C""
9161079Sbosticand
9261079Sbostic.LI "\&""POSIX""
9361079Sbosticlocales, which denote the C language environment.
9458383SbosticA
9558383Sbostic.Fa locale
9658383Sbosticargument of
9758383Sbostic.Dv NULL
9858383Sbosticcauses
9958383Sbostic.Fn setlocale
10058383Sbosticto return the current locale.
10158383SbosticBy default, C programs start in the
10258383Sbostic.Li "\&""C""
10358383Sbosticlocale.
10458383SbosticThe only function in the library that sets the locale is
10558383Sbostic.Fn setlocale ;
10658383Sbosticthe locale is never changed as a side effect of some other routine.
10758383Sbostic.Pp
10858383SbosticThe
10958383Sbostic.Fn localeconv
11058383Sbosticfunction returns a pointer to a structure
11158383Sbosticwhich provides parameters for formatting numbers,
11258383Sbosticespecially currency values:
11358383Sbostic.Bd -literal -offset indent
11458383Sbosticstruct lconv {
11558383Sbostic	char	*decimal_point;
11658383Sbostic	char	*thousands_sep;
11758383Sbostic	char	*grouping;
11858383Sbostic	char	*int_curr_symbol;
11958383Sbostic	char	*currency_symbol;
12058383Sbostic	char	*mon_decimal_point;
12158383Sbostic	char	*mon_thousands_sep;
12258383Sbostic	char	*mon_grouping;
12358383Sbostic	char	*positive_sign;
12458383Sbostic	char	*negative_sign;
12558383Sbostic	char	int_frac_digits;
12658383Sbostic	char	frac_digits;
12758383Sbostic	char	p_cs_precedes;
12858383Sbostic	char	p_sep_by_space;
12958383Sbostic	char	n_cs_precedes;
13058383Sbostic	char	n_sep_by_space;
13158383Sbostic	char	p_sign_posn;
13258383Sbostic	char	n_sign_posn;
13358383Sbostic};
13458383Sbostic.Ed
13558383Sbostic.Pp
13658383SbosticThe individual fields have the following meanings:
13758383Sbostic.Pp
13858383Sbostic.Bl -tag -width mon_decimal_point
13958383Sbostic.It Fa decimal_point
14058383SbosticThe decimal point character, except for currency values.
14158383Sbostic.It Fa thousands_sep
14258383SbosticThe separator between groups of digits
14358383Sbosticbefore the decimal point, except for currency values.
14458383Sbostic.It Fa grouping
14558383SbosticThe sizes of the groups of digits, except for currency values.
14658383SbosticThis is a pointer to a vector of integers, each of size
14758383Sbostic.Va char ,
14858383Sbosticrepresenting group size from low order digit groups
14958383Sbosticto high order (right to left).
15058383SbosticThe list may be terminated with 0 or
15158383Sbostic.Dv CHAR_MAX .
15258383SbosticIf the list is terminated with 0,
15358383Sbosticthe last group size before the 0 is repeated to account for all the digits.
15458383SbosticIf the list is terminated with
15558383Sbostic.Dv CHAR_MAX ,
15658383Sbosticno more grouping is performed.
15758383Sbostic.It Fa int_curr_symbol
15858383SbosticThe standardized international currency symbol.
15958383Sbostic.It Fa currency_symbol
16058383SbosticThe local currency symbol.
16158383Sbostic.It Fa mon_decimal_point
16258383SbosticThe decimal point character for currency values.
16358383Sbostic.It Fa mon_thousands_sep
16458383SbosticThe separator for digit groups in currency values.
16558383Sbostic.It Fa mon_grouping
16658383SbosticLike
16758383Sbostic.Fa grouping
16858383Sbosticbut for currency values.
16958383Sbostic.It Fa positive_sign
17058383SbosticThe character used to denote nonnegative currency values,
17158383Sbosticusually the empty string.
17258383Sbostic.It Fa negative_sign
17358383SbosticThe character used to denote negative currency values,
17458383Sbosticusually a minus sign.
17558383Sbostic.It Fa int_frac_digits
17658383SbosticThe number of digits after the decimal point
17758383Sbosticin an international-style currency value.
17858383Sbostic.It Fa frac_digits
17958383SbosticThe number of digits after the decimal point
18058383Sbosticin the local style for currency values.
18158383Sbostic.It Fa p_cs_precedes
18258383Sbostic1 if the currency symbol precedes the currency value
18358383Sbosticfor nonnegative values, 0 if it follows.
18458383Sbostic.It Fa p_sep_by_space
18558383Sbostic1 if a space is inserted between the currency symbol
18658383Sbosticand the currency value for nonnegative values, 0 otherwise.
18758383Sbostic.It Fa n_cs_precedes
18858383SbosticLike
18958383Sbostic.Fa p_cs_precedes
19058383Sbosticbut for negative values.
19158383Sbostic.It Fa n_sep_by_space
19258383SbosticLike
19358383Sbostic.Fa p_sep_by_space
19458383Sbosticbut for negative values.
19558383Sbostic.It Fa p_sign_posn
19658383SbosticThe location of the
19758383Sbostic.Fa positive_sign
19858383Sbosticwith respect to a nonnegative quantity and the
19958383Sbostic.Fa currency_symbol ,
20058383Sbosticcoded as follows:
20158383Sbostic.Bl -tag -width 3n -compact
20258383Sbostic.It Li 0
20358383SbosticParentheses around the entire string.
20458383Sbostic.It Li 1
20558383SbosticBefore the string.
20658383Sbostic.It Li 2
20758383SbosticAfter the string.
20858383Sbostic.It Li 3
20958383SbosticJust before
21058383Sbostic.Fa currency_symbol .
21158383Sbostic.It Li 4
21258383SbosticJust after
21358383Sbostic.Fa currency_symbol .
21458383Sbostic.El
21558383Sbostic.It Fa n_sign_posn
21658383SbosticLike
21758383Sbostic.Fa p_sign_posn
21858383Sbosticbut for negative currency values.
21958383Sbostic.El
22058383Sbostic.Pp
22158383SbosticUnless mentioned above,
22258383Sbostican empty string as a value for a field
22358383Sbosticindicates a zero length result or
22458383Sbostica value that is not in the current locale.
22558383SbosticA
22658383Sbostic.Dv CHAR_MAX
22758383Sbosticresult similarly denotes an unavailable value.
22858383Sbostic.Sh "RETURN VALUES
22958383SbosticThe
23058383Sbostic.Fn setlocale
23158383Sbosticfunction returns
23258383Sbostic.Dv NULL
23358383Sbosticand fails to change the locale
23458383Sbosticif the given combination of
23558383Sbostic.Fa category
23658383Sbosticand
23758383Sbostic.Fa locale
23858383Sbosticmakes no sense.
23958383SbosticThe
24058383Sbostic.Fn localeconv
24158383Sbosticfunction returns a pointer to a static object
24258383Sbosticwhich may be altered by later calls to
24358383Sbostic.Fn setlocale
24458383Sbosticor
24558383Sbostic.Fn localeconv .
24661079Sbostic.Sh FILES
24761079Sbostic.Bl -tag -width /usr/share/locale/locale/category -compact
24861079Sbostic.It Pa $PATH_LOCALE/\fIlocale\fP/\fIcategory\fP
24961079Sbostic.It Pa /usr/share/locale/\fIlocale\fP/\fIcategory\fP
25061079Sbosticlocale file for the locale \fIlocale\fP
25161079Sbosticand the category \fIcategory\fP.
25261079Sbostic.El
25358383Sbostic.Sh "SEE ALSO
25461079Sbostic.Xr euc 4 ,
25561079Sbostic.Xr mbrune 3 ,
25658383Sbostic.Xr multibyte 3 ,
25761079Sbostic.Xr rune 3 ,
25858383Sbostic.Xr strcoll 3 ,
25961079Sbostic.Xr strxfrm 3 ,
26061079Sbostic.Xr utf2 4
26158383Sbostic.Sh STANDARDS
26258383SbosticThe
26358383Sbostic.Fn setlocale
26458383Sbosticand
26558383Sbostic.Fn localeconv
26658383Sbosticfunctions conform to
26758383Sbostic.St -ansiC .
26858383Sbostic.Sh HISTORY
26958383SbosticThe
27058383Sbostic.Fn setlocale
27158383Sbosticand
27258383Sbostic.Fn localeconv
27362932Sbosticfunctions first appeared in 4.4BSD.
27458383Sbostic.Sh BUGS
27558383SbosticThe current implementation supports only the
27658383Sbostic.Li "\&""C""
27761079Sbosticand
27861079Sbostic.Li "\&""POSIX""
27961079Sbosticlocales for all but the LC_CTYPE locale.
28058383Sbostic.Pp
28158383SbosticIn spite of the gnarly currency support in
28258383Sbostic.Fn localeconv ,
28358383Sbosticthe standards don't include any functions
28458383Sbosticfor generalized currency formatting.
28561079Sbostic.Pp
28661079Sbostic.Dv LC_COLLATE
28761079Sbosticdoes not make sense for many languages.
28861079SbosticUse of
28961079Sbostic.Dv LC_MONETARY
29061079Sbosticcould lead to misleading results until we have a real time currency
29161079Sbosticconversion function.
29261079Sbostic.Dv LC_NUMERIC
29361079Sbosticand
29461079Sbostic.Dv LC_TIME
29561079Sbosticare personal choices and should not be wrapped up with the other categories.
296