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