Home | History | Annotate | Line # | Download | only in locale
localeconv.c revision 1.6
      1  1.1  cgd /*
      2  1.6  jtc  * Written by J.T. Conklin <jtc (at) netbsd.org>.
      3  1.6  jtc  * Public domain.
      4  1.1  cgd  */
      5  1.1  cgd 
      6  1.1  cgd #if defined(LIBC_SCCS) && !defined(lint)
      7  1.6  jtc static char *rcsid = "$Id: localeconv.c,v 1.6 1995/04/28 23:19:32 jtc Exp $";
      8  1.1  cgd #endif /* LIBC_SCCS and not lint */
      9  1.1  cgd 
     10  1.5  jtc #include <sys/localedef.h>
     11  1.1  cgd #include <locale.h>
     12  1.1  cgd 
     13  1.4  jtc /*
     14  1.4  jtc  * The localeconv() function constructs a struct lconv from the current
     15  1.4  jtc  * monetary and numeric locales.
     16  1.4  jtc  *
     17  1.4  jtc  * Because localeconv() may be called many times (especially by library
     18  1.4  jtc  * routines like printf() & strtod()), the approprate members of the
     19  1.4  jtc  * lconv structure are computed only when the monetary or numeric
     20  1.4  jtc  * locale has been changed.
     21  1.4  jtc  */
     22  1.4  jtc int __mlocale_changed = 1;
     23  1.4  jtc int __nlocale_changed = 1;
     24  1.4  jtc 
     25  1.1  cgd /*
     26  1.1  cgd  * Return the current locale conversion.
     27  1.1  cgd  */
     28  1.1  cgd struct lconv *
     29  1.1  cgd localeconv()
     30  1.1  cgd {
     31  1.4  jtc     static struct lconv ret;
     32  1.4  jtc 
     33  1.4  jtc     if (__mlocale_changed) {
     34  1.4  jtc 	/* LC_MONETARY */
     35  1.4  jtc 	ret.int_curr_symbol	= _CurrentMonetaryLocale->int_curr_symbol;
     36  1.4  jtc 	ret.currency_symbol	= _CurrentMonetaryLocale->currency_symbol;
     37  1.4  jtc 	ret.mon_decimal_point	= _CurrentMonetaryLocale->mon_decimal_point;
     38  1.4  jtc 	ret.mon_thousands_sep	= _CurrentMonetaryLocale->mon_thousands_sep;
     39  1.4  jtc 	ret.mon_grouping	= _CurrentMonetaryLocale->mon_grouping;
     40  1.4  jtc 	ret.positive_sign	= _CurrentMonetaryLocale->positive_sign;
     41  1.4  jtc 	ret.negative_sign	= _CurrentMonetaryLocale->negative_sign;
     42  1.4  jtc 	ret.int_frac_digits	= _CurrentMonetaryLocale->int_frac_digits;
     43  1.4  jtc 	ret.frac_digits		= _CurrentMonetaryLocale->frac_digits;
     44  1.4  jtc 	ret.p_cs_precedes	= _CurrentMonetaryLocale->p_cs_precedes;
     45  1.4  jtc 	ret.p_sep_by_space	= _CurrentMonetaryLocale->p_sep_by_space;
     46  1.4  jtc 	ret.n_cs_precedes	= _CurrentMonetaryLocale->n_cs_precedes;
     47  1.4  jtc 	ret.n_sep_by_space	= _CurrentMonetaryLocale->n_sep_by_space;
     48  1.4  jtc 	ret.p_sign_posn		= _CurrentMonetaryLocale->p_sign_posn;
     49  1.4  jtc 	ret.n_sign_posn		= _CurrentMonetaryLocale->n_sign_posn;
     50  1.4  jtc 	__mlocale_changed = 0;
     51  1.4  jtc     }
     52  1.4  jtc 
     53  1.4  jtc     if (__nlocale_changed) {
     54  1.4  jtc 	/* LC_NUMERIC */
     55  1.4  jtc 	ret.decimal_point	= (char *) _CurrentNumericLocale->decimal_point;
     56  1.4  jtc 	ret.thousands_sep	= (char *) _CurrentNumericLocale->thousands_sep;
     57  1.4  jtc 	ret.grouping		= (char *) _CurrentNumericLocale->grouping;
     58  1.4  jtc 	__nlocale_changed = 0;
     59  1.4  jtc     }
     60  1.1  cgd 
     61  1.4  jtc     return (&ret);
     62  1.1  cgd }
     63