//	Zinc Application Framework - M_LOC.CPP
//	COPYRIGHT (C) 1990-1999.  All Rights Reserved.
//	Zinc Software Incorporated.  Pleasant Grove, Utah  USA

#include <z_cset.hpp>
#include <z_loc.hpp>
#include <z_stdlib.hpp>
#include <z_ctype.hpp>
#include <z_string.hpp>
#include <locale.h>
#include <limits.h>
#define ZAF_LOCALE_DATA_INFO
#include "loc_def.cpp"

// -----  Support routines --------------------------------------------------

bool ZafLocaleData::OSLocaleInformation(ZafLocaleStruct &localeInfo)
{
	// Start with default information.
	localeInfo.posCurrencyPrecedes = defaultLocale.posCurrencyPrecedes;
	localeInfo.negCurrencyPrecedes = defaultLocale.negCurrencyPrecedes;
	localeInfo.fractionDigits = defaultLocale.fractionDigits;
	localeInfo.intFractionDigits = defaultLocale.intFractionDigits;
	localeInfo.posSignPrecedes = defaultLocale.posSignPrecedes;
	localeInfo.posSpaceSeparation = defaultLocale.posSpaceSeparation;
	localeInfo.negSignPrecedes = defaultLocale.negSignPrecedes;
	localeInfo.negSpaceSeparation = defaultLocale.negSpaceSeparation;
	strcpy(localeInfo.creditLeftParen, defaultLocale.creditLeftParen);
	strcpy(localeInfo.creditRightParen, defaultLocale.creditRightParen);
	strcpy(localeInfo.integerStringInputFormat, defaultLocale.integerStringInputFormat);
	strcpy(localeInfo.integerStringOutputFormat, defaultLocale.integerStringOutputFormat);
	strcpy(localeInfo.realStringInputFormat, defaultLocale.realStringInputFormat);
	strcpy(localeInfo.realStringOutputFormat, defaultLocale.realStringOutputFormat);
	strcpy(localeInfo.timeStringInputFormat, defaultLocale.timeStringInputFormat);
	strcpy(localeInfo.timeStringOutputFormat, defaultLocale.timeStringOutputFormat);
	strcpy(localeInfo.time12StringOutputFormat, defaultLocale.time12StringOutputFormat);
	strcpy(localeInfo.dateStringInputFormat, defaultLocale.dateStringInputFormat);
	strcpy(localeInfo.dateStringOutputFormat, defaultLocale.dateStringOutputFormat);
	strcpy(localeInfo.dateTimeStringInputFormat, defaultLocale.dateTimeStringInputFormat);
	strcpy(localeInfo.dateTimeStringOutputFormat, defaultLocale.dateTimeStringOutputFormat);
	strcpy(localeInfo.defDigits, defaultLocale.defDigits);
	strcpy(localeInfo.altDigits, defaultLocale.altDigits);
	strcpy(localeInfo.timeSeparator, defaultLocale.timeSeparator);
	strcpy(localeInfo.dateSeparator, defaultLocale.dateSeparator);

	// Get the locale.
	setlocale(LC_ALL, "");
	struct lconv *conv = localeconv();

	zafCodeSet->ConvertToZafString(conv->decimal_point, localeInfo.decimalSeparator);
	zafCodeSet->ConvertToZafString(conv->mon_decimal_point, localeInfo.monDecimalSeparator);
	zafCodeSet->ConvertToZafString(conv->thousands_sep, localeInfo.thousandsSeparator);
	zafCodeSet->ConvertToZafString(conv->mon_thousands_sep, localeInfo.monThousandsSeparator);
	zafCodeSet->ConvertToZafString(conv->currency_symbol, localeInfo.currencySymbol);
	strcpy(localeInfo.grouping, conv->grouping);
	strcpy(localeInfo.monGrouping, conv->mon_grouping);
	zafCodeSet->ConvertToZafString(conv->int_curr_symbol, localeInfo.intCurrencySymbol);
	if (conv->p_cs_precedes != CHAR_MAX)
		localeInfo.posCurrencyPrecedes = conv->p_cs_precedes;
	if (conv->n_cs_precedes != CHAR_MAX)
		localeInfo.negCurrencyPrecedes = conv->n_cs_precedes;
	if (conv->frac_digits != CHAR_MAX)
		localeInfo.fractionDigits = conv->frac_digits;
	if (conv->int_frac_digits != CHAR_MAX)
		localeInfo.intFractionDigits = conv->int_frac_digits;
	zafCodeSet->ConvertToZafString(conv->positive_sign, localeInfo.positiveSign);
	if (conv->p_sign_posn != CHAR_MAX)
		localeInfo.posSignPrecedes = conv->p_sign_posn;
	if (conv->p_sep_by_space != CHAR_MAX)
		localeInfo.posSpaceSeparation = conv->p_sep_by_space;
	zafCodeSet->ConvertToZafString(conv->negative_sign, localeInfo.negativeSign);
	if (conv->n_sign_posn != CHAR_MAX)
		localeInfo.negSignPrecedes = conv->n_sign_posn;
	if (conv->n_sep_by_space != CHAR_MAX)
		localeInfo.negSpaceSeparation = conv->n_sep_by_space;

	// Return success.
	return (true);
}

