localeconv.c revision 1.4 1 /*
2 * Copyright (c) 1993,94 Winning Strategies, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Winning Strategies, Inc.
16 * 4. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #if defined(LIBC_SCCS) && !defined(lint)
32 static char *rcsid = "$Id: localeconv.c,v 1.4 1994/05/25 01:49:33 jtc Exp $";
33 #endif /* LIBC_SCCS and not lint */
34
35 #define _LOCALE_PRIVATE
36 #include <locale.h>
37
38 /*
39 * The localeconv() function constructs a struct lconv from the current
40 * monetary and numeric locales.
41 *
42 * Because localeconv() may be called many times (especially by library
43 * routines like printf() & strtod()), the approprate members of the
44 * lconv structure are computed only when the monetary or numeric
45 * locale has been changed.
46 */
47 int __mlocale_changed = 1;
48 int __nlocale_changed = 1;
49
50 /*
51 * Return the current locale conversion.
52 */
53 struct lconv *
54 localeconv()
55 {
56 static struct lconv ret;
57
58 if (__mlocale_changed) {
59 /* LC_MONETARY */
60 ret.int_curr_symbol = _CurrentMonetaryLocale->int_curr_symbol;
61 ret.currency_symbol = _CurrentMonetaryLocale->currency_symbol;
62 ret.mon_decimal_point = _CurrentMonetaryLocale->mon_decimal_point;
63 ret.mon_thousands_sep = _CurrentMonetaryLocale->mon_thousands_sep;
64 ret.mon_grouping = _CurrentMonetaryLocale->mon_grouping;
65 ret.positive_sign = _CurrentMonetaryLocale->positive_sign;
66 ret.negative_sign = _CurrentMonetaryLocale->negative_sign;
67 ret.int_frac_digits = _CurrentMonetaryLocale->int_frac_digits;
68 ret.frac_digits = _CurrentMonetaryLocale->frac_digits;
69 ret.p_cs_precedes = _CurrentMonetaryLocale->p_cs_precedes;
70 ret.p_sep_by_space = _CurrentMonetaryLocale->p_sep_by_space;
71 ret.n_cs_precedes = _CurrentMonetaryLocale->n_cs_precedes;
72 ret.n_sep_by_space = _CurrentMonetaryLocale->n_sep_by_space;
73 ret.p_sign_posn = _CurrentMonetaryLocale->p_sign_posn;
74 ret.n_sign_posn = _CurrentMonetaryLocale->n_sign_posn;
75 __mlocale_changed = 0;
76 }
77
78 if (__nlocale_changed) {
79 /* LC_NUMERIC */
80 ret.decimal_point = (char *) _CurrentNumericLocale->decimal_point;
81 ret.thousands_sep = (char *) _CurrentNumericLocale->thousands_sep;
82 ret.grouping = (char *) _CurrentNumericLocale->grouping;
83 __nlocale_changed = 0;
84 }
85
86 return (&ret);
87 }
88