Пример #1
0
int
__monetary_load_locale(const char *name) {

	int ret;
	__mlocale_changed = 1;
	ret = __part_load_locale(name, &_monetary_using_locale,
		_monetary_locale_buf, "LC_MONETARY",
		LCMONETARY_SIZE, LCMONETARY_SIZE,
		(const char **)&_monetary_locale);
	if (ret == 0 && _monetary_using_locale) {
		_monetary_locale.mon_grouping =
		     __fix_locale_grouping_str(_monetary_locale.mon_grouping);

#define M_ASSIGN_CHAR(NAME) (((char *)_monetary_locale.NAME)[0] = \
			     cnv(_monetary_locale.NAME))

		M_ASSIGN_CHAR(int_frac_digits);
		M_ASSIGN_CHAR(frac_digits);
		M_ASSIGN_CHAR(p_cs_precedes);
		M_ASSIGN_CHAR(p_sep_by_space);
		M_ASSIGN_CHAR(n_cs_precedes);
		M_ASSIGN_CHAR(n_sep_by_space);
		M_ASSIGN_CHAR(p_sign_posn);
		M_ASSIGN_CHAR(n_sign_posn);
	}
	return ret;
}
Пример #2
0
__private_extern__ int
__numeric_load_locale(const char *name, locale_t loc)
{
	int ret;
	struct __xlocale_st_numeric *xp;
	static struct __xlocale_st_numeric *cache = NULL;

	/* 'name' must be already checked. */
	if (strcmp(name, "C") == 0 || strcmp(name, "POSIX") == 0) {
		if (!loc->_numeric_using_locale)
			return (_LDP_CACHE);
		loc->_numeric_using_locale = 0;
		XL_RELEASE(loc->__lc_numeric);
		loc->__lc_numeric = NULL;
		loc->__nlocale_changed = 1;
		return (_LDP_CACHE);
	}

	if (loc->_numeric_using_locale && strcmp(name, loc->__lc_numeric->_numeric_locale_buf) == 0)
		return (_LDP_CACHE);
	/*
	 * If the locale name is the same as our cache, use the cache.
	 */
	if (cache && cache->_numeric_locale_buf && strcmp(name, cache->_numeric_locale_buf) == 0) {
		loc->_numeric_using_locale = 1;
		XL_RELEASE(loc->__lc_numeric);
		loc->__lc_numeric = cache;
		XL_RETAIN(loc->__lc_numeric);
		loc->__nlocale_changed = 1;
		return (_LDP_CACHE);
	}
	if ((xp = (struct __xlocale_st_numeric *)malloc(sizeof(*xp))) == NULL)
		return _LDP_ERROR;
	xp->__refcount = 1;
	xp->__free_extra = (__free_extra_t)__ldpart_free_extra;
	xp->_numeric_locale_buf = NULL;

	ret = __part_load_locale(name, &loc->_numeric_using_locale,
		&xp->_numeric_locale_buf, "LC_NUMERIC",
		LCNUMERIC_SIZE, LCNUMERIC_SIZE,
		(const char **)&xp->_numeric_locale);
	if (ret != _LDP_ERROR)
		loc->__nlocale_changed = 1;
	else
		free(xp);
	if (ret == _LDP_LOADED) {
		/* Can't be empty according to C99 */
		if (*xp->_numeric_locale.decimal_point == '\0')
			xp->_numeric_locale.decimal_point =
			    _C_numeric_locale.decimal_point;
		xp->_numeric_locale.grouping =
		    __fix_locale_grouping_str(xp->_numeric_locale.grouping);
		XL_RELEASE(loc->__lc_numeric);
		loc->__lc_numeric = xp;
		XL_RELEASE(cache);
		cache = xp;
		XL_RETAIN(cache);
	}
	return (ret);
}
Пример #3
0
int
__monetary_load_locale(const char *name)
{
	int ret;

	ret = __part_load_locale(name, &_monetary_using_locale,
		_monetary_locale_buf, "LC_MONETARY",
		LCMONETARY_SIZE_FULL, LCMONETARY_SIZE_MIN,
		(const char **)&_monetary_locale);
	if (ret != _LDP_ERROR)
		__mlocale_changed = 1;
	if (ret == _LDP_LOADED) {
		_monetary_locale.mon_grouping =
		     __fix_locale_grouping_str(_monetary_locale.mon_grouping);

#define M_ASSIGN_CHAR(NAME) (((char *)_monetary_locale.NAME)[0] = \
			     cnv(_monetary_locale.NAME))

		M_ASSIGN_CHAR(int_frac_digits);
		M_ASSIGN_CHAR(frac_digits);
		M_ASSIGN_CHAR(p_cs_precedes);
		M_ASSIGN_CHAR(p_sep_by_space);
		M_ASSIGN_CHAR(n_cs_precedes);
		M_ASSIGN_CHAR(n_sep_by_space);
		M_ASSIGN_CHAR(p_sign_posn);
		M_ASSIGN_CHAR(n_sign_posn);

		/*
		 * The six additional C99 international monetary formatting
		 * parameters default to the national parameters when
		 * reading FreeBSD 4 LC_MONETARY data files.
		 */
#define	M_ASSIGN_ICHAR(NAME)						\
		do {							\
			if (_monetary_locale.int_##NAME == NULL)	\
				_monetary_locale.int_##NAME =		\
				    _monetary_locale.NAME;		\
			else						\
				M_ASSIGN_CHAR(int_##NAME);		\
		} while (0)

		M_ASSIGN_ICHAR(p_cs_precedes);
		M_ASSIGN_ICHAR(n_cs_precedes);
		M_ASSIGN_ICHAR(p_sep_by_space);
		M_ASSIGN_ICHAR(n_sep_by_space);
		M_ASSIGN_ICHAR(p_sign_posn);
		M_ASSIGN_ICHAR(n_sign_posn);
	}
	return (ret);
}
Пример #4
0
int
__ctype_load_locale(const char *name, void *f_wctomb, const char *charset,
		    int mb_cur_max)
{
	int ret;

#ifdef __CYGWIN__
	extern int __set_lc_ctype_from_win (const char *,
					    const struct lc_ctype_T *,
					    struct lc_ctype_T *, char **,
					    void *, const char *, int);
	int old_ctype_using_locale = _ctype_using_locale;
	_ctype_using_locale = 0;
	ret = __set_lc_ctype_from_win (name, &_C_ctype_locale, &_ctype_locale,
				       &_ctype_locale_buf, f_wctomb, charset,
				       mb_cur_max);
	/* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */
	if (ret < 0)
	  _ctype_using_locale = old_ctype_using_locale;
	else
	  {
	    _ctype_using_locale = ret;
	    ret = 0;
	  }
#elif !defined (__HAVE_LOCALE_INFO_EXTENDED__)
	if (!strcmp (name, "C"))
	  _ctype_using_locale = 0;
	else
	  {
			char *mbc;
	    _ctype_locale.codeset = strcpy (_ctype_locale_buf, charset);
	    mbc = _ctype_locale_buf + _CTYPE_BUF_SIZE - 2;
	    mbc[0] = mb_cur_max;
	    mbc[1] = '\0';
	    _ctype_locale.mb_cur_max = mbc;
	    _ctype_using_locale = 1;
	  }
	ret = 0;
#else
	ret = __part_load_locale(name, &_ctype_using_locale,
		_ctype_locale_buf, "LC_CTYPE",
		LCCTYPE_SIZE, LCCTYPE_SIZE,
		(const char **)&_ctype_locale);
	if (ret == 0 && _ctype_using_locale)
		_ctype_locale.grouping =
			__fix_locale_grouping_str(_ctype_locale.grouping);
#endif
	return ret;
}
Пример #5
0
int
__numeric_load_locale(const char *name) {

	int ret;

	__nlocale_changed = 1;
	ret = __part_load_locale(name, &_numeric_using_locale,
		_numeric_locale_buf, "LC_NUMERIC",
		LCNUMERIC_SIZE, LCNUMERIC_SIZE,
		(const char **)&_numeric_locale);
	if (ret == 0 && _numeric_using_locale)
		_numeric_locale.grouping =
			__fix_locale_grouping_str(_numeric_locale.grouping);
	return ret;
}
Пример #6
0
int
__numeric_load_locale(const char *name)
{
	int ret;

	ret = __part_load_locale(name, &_numeric_using_locale,
		&_numeric_locale_buf, "LC_NUMERIC",
		LCNUMERIC_SIZE, LCNUMERIC_SIZE,
		(const char **)&_numeric_locale);
	if (ret != _LDP_ERROR)
		__nlocale_changed = 1;
	if (ret == _LDP_LOADED) {
		/* Can't be empty according to C99 */
		if (*_numeric_locale.decimal_point == '\0')
			_numeric_locale.decimal_point =
			    _C_numeric_locale.decimal_point;
		_numeric_locale.grouping =
		    __fix_locale_grouping_str(_numeric_locale.grouping);
	}
	return (ret);
}
Пример #7
0
int
__numeric_load_locale(const char *name , void *f_wctomb, const char *charset)
{
	int ret;

#ifdef __CYGWIN__
	extern int __set_lc_numeric_from_win (const char *,
					      const struct lc_numeric_T *,
					      struct lc_numeric_T *, char **,
					      void *, const char *);
	int old_numeric_using_locale = _numeric_using_locale;
	_numeric_using_locale = 0;
	ret = __set_lc_numeric_from_win (name, &_C_numeric_locale,
					 &_numeric_locale, &_numeric_locale_buf,
					 f_wctomb, charset);
	/* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */
	if (ret < 0)
	  _numeric_using_locale = old_numeric_using_locale;
	else
	  {
	    _numeric_using_locale = ret;
	    __nlocale_changed = 1;
	    ret = 0;
	  }
#else
	__nlocale_changed = 1;
	ret = __part_load_locale(name, &_numeric_using_locale,
		_numeric_locale_buf, "LC_NUMERIC",
		LCNUMERIC_SIZE, LCNUMERIC_SIZE,
		(const char **)&_numeric_locale);
	if (ret == 0 && _numeric_using_locale)
		_numeric_locale.grouping =
			__fix_locale_grouping_str(_numeric_locale.grouping);
#endif
	return ret;
}
Пример #8
0
struct locdata *
__lc_monetary_load(const char *name)
{
	int ret;
	int clen;
	struct lc_monetary	*lmon;
	struct locdata		*ldata;

	if ((ldata = __locdata_alloc(name, sizeof (*lmon))) == NULL) {
		return (NULL);
	}
	lmon = ldata->l_data[0];

	ret = __part_load_locale(name, (char **)&ldata->l_data[1],
	    "LC_MONETARY", LCMONETARY_SIZE_FULL, LCMONETARY_SIZE_MIN,
	    (const char **)lmon);

	if (ret != _LDP_LOADED) {
		__locdata_free(ldata);
		errno = EINVAL;
		return (NULL);
	}

	/* special storage for currency string */
	clen = strlen(lmon->currency_symbol) + 2;
	ldata->l_data[2] = libc_malloc(clen);
	lmon->crncystr = ldata->l_data[2];

	lmon->mon_grouping = __fix_locale_grouping_str(lmon->mon_grouping);

#define	M_ASSIGN_CHAR(NAME) \
	(((char *)lmon->NAME)[0] = cnv(lmon->NAME))

	M_ASSIGN_CHAR(int_frac_digits);
	M_ASSIGN_CHAR(frac_digits);
	M_ASSIGN_CHAR(p_cs_precedes);
	M_ASSIGN_CHAR(p_sep_by_space);
	M_ASSIGN_CHAR(n_cs_precedes);
	M_ASSIGN_CHAR(n_sep_by_space);
	M_ASSIGN_CHAR(p_sign_posn);
	M_ASSIGN_CHAR(n_sign_posn);

	/*
	 * The six additional C99 international monetary formatting
	 * parameters default to the national parameters when
	 * reading FreeBSD LC_MONETARY data files.
	 */
#define	M_ASSIGN_ICHAR(NAME)				\
	if (lmon->int_##NAME == NULL)			\
		lmon->int_##NAME = lmon->NAME;		\
	else						\
		M_ASSIGN_CHAR(int_##NAME);

	M_ASSIGN_ICHAR(p_cs_precedes);
	M_ASSIGN_ICHAR(n_cs_precedes);
	M_ASSIGN_ICHAR(p_sep_by_space);
	M_ASSIGN_ICHAR(n_sep_by_space);
	M_ASSIGN_ICHAR(p_sign_posn);
	M_ASSIGN_ICHAR(n_sign_posn);

	/*
	 * Now calculate the currency string (CRNCYSTR) for nl_langinfo.
	 * This is a legacy SUSv2 interface.
	 */
	if ((lmon->p_cs_precedes[0] == lmon->n_cs_precedes[0]) &&
	    (lmon->currency_symbol[0] != '\0')) {
		char sign = '\0';
		switch (lmon->p_cs_precedes[0]) {
		case 0:
			sign = '+';
			break;
		case 1:
			sign = '-';
			break;
		case CHAR_MAX:
			/*
			 * Substitute currency string for radix character.
			 * To the best of my knowledge, no locale uses this.
			 */
			if (strcmp(lmon->mon_decimal_point,
			    lmon->currency_symbol) == 0)
				sign = '.';
			break;
		}
		(void) snprintf(lmon->crncystr, clen, "%c%s", sign,
		    lmon->currency_symbol);
	}

	return (ldata);
}