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