1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/libc/src/lmonetary.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,182 @@
1.4 +/*
1.5 +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description: Contains the source for all the system calls in libc
1.18 + *
1.19 + *
1.20 +*/
1.21 +
1.22 +
1.23 +#include <limits.h>
1.24 +#include <stdlib.h>
1.25 +#include <sys/cdefs.h>
1.26 +#include "localeinfo.h"
1.27 +#include "lmonetary.h"
1.28 +
1.29 +#if (defined(__SYMBIAN32__) && (defined(__WINSCW__) || defined(__WINS__)))
1.30 +#include "libc_wsd_defs.h"
1.31 +#endif
1.32 +
1.33 +// Muzibour : Include #include <sys/cdefs.h> and then use the macro __BEGIN_DECLS
1.34 +__BEGIN_DECLS
1.35 +extern int __mlocale_changed;
1.36 +#ifdef EMULATOR
1.37 +int *GET_WSD_VAR_NAME(__mlocale_changed, g)();
1.38 +#define __mlocale_changed (*GET_WSD_VAR_NAME(__mlocale_changed, g)())
1.39 +#endif //EMULATOR
1.40 +__END_DECLS
1.41 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.42 +__BEGIN_DECLS
1.43 +extern unsigned char __clocale_set;
1.44 +#ifdef EMULATOR
1.45 +unsigned char *GET_WSD_VAR_NAME(__clocale_set, g)();
1.46 +#define __clocale_set (*GET_WSD_VAR_NAME(__clocale_set, g)())
1.47 +#endif //EMULATOR
1.48 +__END_DECLS
1.49 +#endif
1.50 +#ifndef EMULATOR
1.51 +int _monetary_using_locale;
1.52 +#else //EMULATOR
1.53 +
1.54 +GET_GLOBAL_VAR_FROM_TLS(_monetary_using_locale, int)
1.55 +#define _monetary_using_locale (*GET_WSD_VAR_NAME(_monetary_using_locale, g)())
1.56 +#endif //EMULATOR
1.57 +
1.58 +#ifndef EMULATOR
1.59 +static char empty[] = "";
1.60 +static char numempty[] = { CHAR_MAX, '\0'};
1.61 +#else //EMULATOR
1.62 +static const char empty[] = "";
1.63 +static const char numempty[] = { CHAR_MAX, '\0'};
1.64 +
1.65 +#endif //EMULATOR
1.66 +
1.67 +static const struct lc_monetary_T _C_monetary_locale = {
1.68 + empty, /* int_curr_symbol */
1.69 + empty, /* currency_symbol */
1.70 + empty, /* mon_decimal_point */
1.71 + empty, /* mon_thousands_sep */
1.72 + numempty, /* mon_grouping */
1.73 + empty, /* positive_sign */
1.74 + empty, /* negative_sign */
1.75 + numempty, /* int_frac_digits */
1.76 + numempty, /* frac_digits */
1.77 + numempty, /* p_cs_precedes */
1.78 + numempty, /* p_sep_by_space */
1.79 + numempty, /* n_cs_precedes */
1.80 + numempty, /* n_sep_by_space */
1.81 + numempty, /* p_sign_posn */
1.82 + numempty, /* n_sign_posn */
1.83 + numempty, /* int_p_cs_precedes */
1.84 + numempty, /* int_n_cs_precedes */
1.85 + numempty, /* int_p_sep_by_space */
1.86 + numempty, /* int_n_sep_by_space */
1.87 + numempty, /* int_p_sign_posn */
1.88 + numempty /* int_n_sign_posn */
1.89 +};
1.90 +
1.91 +
1.92 +
1.93 +int
1.94 +__monetary_load_locale(const char* localeName)
1.95 +{
1.96 + //Get an instance of locale object
1.97 + CLocale* locale = CLocale::GetInstance();
1.98 + //Load the monetary(LC_MONETARY category) information
1.99 + TInt ret = KErrNone;
1.100 + TRAPD(result,ret = locale->MonetaryLoadLocaleL(localeName));
1.101 + if ((result != KErrNone) || (ret == -1))
1.102 + {
1.103 + return -1;
1.104 + }
1.105 + __mlocale_changed = 1;
1.106 + _monetary_using_locale = 1;
1.107 +
1.108 + return 0;
1.109 +}
1.110 +
1.111 +struct lc_monetary_T *
1.112 +__get_current_monetary_locale(void)
1.113 +{
1.114 + //Retreive the monetary(LC_MONETARY category) information
1.115 + if(_monetary_using_locale)
1.116 + {
1.117 + return (CLocale::GetCurrentMonetaryLocale());
1.118 + }
1.119 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.120 + else if(__clocale_set)
1.121 +#endif
1.122 + //return POSIX C locale monetary(LC_MONETARY category) information
1.123 + return ((struct lc_monetary_T *)&_C_monetary_locale);
1.124 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.125 + else
1.126 + {
1.127 + CLocale *l=CLocale::GetInstance();
1.128 + TRAPD(result,l->MonetaryLoadLocaleL(NULL));
1.129 + if (result != KErrNone)
1.130 + {
1.131 + return NULL;
1.132 + }
1.133 + return (CLocale::GetCurrentMonetaryLocale());
1.134 + }
1.135 +#endif
1.136 +}
1.137 +
1.138 +#ifdef LOCALE_DEBUG
1.139 +void
1.140 +monetdebug() {
1.141 +printf( "int_curr_symbol = %s\n"
1.142 + "currency_symbol = %s\n"
1.143 + "mon_decimal_point = %s\n"
1.144 + "mon_thousands_sep = %s\n"
1.145 + "mon_grouping = %s\n"
1.146 + "positive_sign = %s\n"
1.147 + "negative_sign = %s\n"
1.148 + "int_frac_digits = %d\n"
1.149 + "frac_digits = %d\n"
1.150 + "p_cs_precedes = %d\n"
1.151 + "p_sep_by_space = %d\n"
1.152 + "n_cs_precedes = %d\n"
1.153 + "n_sep_by_space = %d\n"
1.154 + "p_sign_posn = %d\n"
1.155 + "n_sign_posn = %d\n",
1.156 + "int_p_cs_precedes = %d\n"
1.157 + "int_p_sep_by_space = %d\n"
1.158 + "int_n_cs_precedes = %d\n"
1.159 + "int_n_sep_by_space = %d\n"
1.160 + "int_p_sign_posn = %d\n"
1.161 + "int_n_sign_posn = %d\n",
1.162 + _monetary_locale.int_curr_symbol,
1.163 + _monetary_locale.currency_symbol,
1.164 + _monetary_locale.mon_decimal_point,
1.165 + _monetary_locale.mon_thousands_sep,
1.166 + _monetary_locale.mon_grouping,
1.167 + _monetary_locale.positive_sign,
1.168 + _monetary_locale.negative_sign,
1.169 + _monetary_locale.int_frac_digits[0],
1.170 + _monetary_locale.frac_digits[0],
1.171 + _monetary_locale.p_cs_precedes[0],
1.172 + _monetary_locale.p_sep_by_space[0],
1.173 + _monetary_locale.n_cs_precedes[0],
1.174 + _monetary_locale.n_sep_by_space[0],
1.175 + _monetary_locale.p_sign_posn[0],
1.176 + _monetary_locale.n_sign_posn[0],
1.177 + _monetary_locale.int_p_cs_precedes[0],
1.178 + _monetary_locale.int_p_sep_by_space[0],
1.179 + _monetary_locale.int_n_cs_precedes[0],
1.180 + _monetary_locale.int_n_sep_by_space[0],
1.181 + _monetary_locale.int_p_sign_posn[0],
1.182 + _monetary_locale.int_n_sign_posn[0]
1.183 +);
1.184 +}
1.185 +#endif /* LOCALE_DEBUG */