[BACK]Return to localeconv.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / locale

File: [cvs.NetBSD.org] / src / lib / libc / locale / localeconv.c (download)

Revision 1.12, Fri Jan 2 21:53:49 2004 UTC (16 years, 4 months ago) by itojun
Branch: MAIN
CVS Tags: netbsd-3-base, netbsd-3-1-RELEASE, netbsd-3-1-RC4, netbsd-3-1-RC3, netbsd-3-1-RC2, netbsd-3-1-RC1, netbsd-3-1-1-RELEASE, netbsd-3-1, netbsd-3-0-RELEASE, netbsd-3-0-RC6, netbsd-3-0-RC5, netbsd-3-0-RC4, netbsd-3-0-RC3, netbsd-3-0-RC2, netbsd-3-0-RC1, netbsd-3-0-3-RELEASE, netbsd-3-0-2-RELEASE, netbsd-3-0-1-RELEASE, netbsd-3-0, netbsd-3, netbsd-2-base, netbsd-2-1-RELEASE, netbsd-2-1-RC6, netbsd-2-1-RC5, netbsd-2-1-RC4, netbsd-2-1-RC3, netbsd-2-1-RC2, netbsd-2-1-RC1, netbsd-2-1, netbsd-2-0-base, netbsd-2-0-RELEASE, netbsd-2-0-RC5, netbsd-2-0-RC4, netbsd-2-0-RC3, netbsd-2-0-RC2, netbsd-2-0-RC1, netbsd-2-0-3-RELEASE, netbsd-2-0-2-RELEASE, netbsd-2-0-1-RELEASE, netbsd-2-0, netbsd-2
Changes since 1.11: +48 -40 lines

KNF

/*	$NetBSD: localeconv.c,v 1.12 2004/01/02 21:53:49 itojun Exp $	*/

/*
 * Written by J.T. Conklin <jtc@NetBSD.org>.
 * Public domain.
 */

#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: localeconv.c,v 1.12 2004/01/02 21:53:49 itojun Exp $");
#endif /* LIBC_SCCS and not lint */

#include <sys/localedef.h>
#include <locale.h>

/* 
 * The localeconv() function constructs a struct lconv from the current
 * monetary and numeric locales.
 *
 * Because localeconv() may be called many times (especially by library
 * routines like printf() & strtod()), the approprate members of the 
 * lconv structure are computed only when the monetary or numeric 
 * locale has been changed.
 */
int __mlocale_changed = 1;
int __nlocale_changed = 1;

/*
 * Return the current locale conversion.
 */
struct lconv *
localeconv()
{
	static struct lconv ret;

	if (__mlocale_changed) {
		/* LC_MONETARY */
		ret.int_curr_symbol = _CurrentMonetaryLocale->int_curr_symbol;
		ret.currency_symbol = _CurrentMonetaryLocale->currency_symbol;
		ret.mon_decimal_point =
		    _CurrentMonetaryLocale->mon_decimal_point;
		ret.mon_thousands_sep =
		    _CurrentMonetaryLocale->mon_thousands_sep;
		ret.mon_grouping = _CurrentMonetaryLocale->mon_grouping;
		ret.positive_sign = _CurrentMonetaryLocale->positive_sign;
		ret.negative_sign = _CurrentMonetaryLocale->negative_sign;
		ret.int_frac_digits = _CurrentMonetaryLocale->int_frac_digits;
		ret.frac_digits = _CurrentMonetaryLocale->frac_digits;
		ret.p_cs_precedes = _CurrentMonetaryLocale->p_cs_precedes;
		ret.p_sep_by_space = _CurrentMonetaryLocale->p_sep_by_space;
		ret.n_cs_precedes = _CurrentMonetaryLocale->n_cs_precedes;
		ret.n_sep_by_space = _CurrentMonetaryLocale->n_sep_by_space;
		ret.p_sign_posn = _CurrentMonetaryLocale->p_sign_posn;
		ret.n_sign_posn = _CurrentMonetaryLocale->n_sign_posn;
		ret.int_p_cs_precedes =
		    _CurrentMonetaryLocale->int_p_cs_precedes;
		ret.int_n_cs_precedes =
		    _CurrentMonetaryLocale->int_n_cs_precedes;
		ret.int_p_sep_by_space =
		    _CurrentMonetaryLocale->int_p_sep_by_space;
		ret.int_n_sep_by_space =
		    _CurrentMonetaryLocale->int_n_sep_by_space;
		ret.int_p_sign_posn = _CurrentMonetaryLocale->int_p_sign_posn;
		ret.int_n_sign_posn = _CurrentMonetaryLocale->int_n_sign_posn;
		__mlocale_changed = 0;
	}

	if (__nlocale_changed) {
		/* LC_NUMERIC */
		/* LINTED const castaway */
		ret.decimal_point =
		    (char *)_CurrentNumericLocale->decimal_point;
		/* LINTED const castaway */
		ret.thousands_sep =
		    (char *)_CurrentNumericLocale->thousands_sep;
		/* LINTED const castaway */
		ret.grouping = (char *) _CurrentNumericLocale->grouping;
		__nlocale_changed = 0;
	}

	return (&ret);
}