os/ossrv/genericopenlibs/openenvcore/libc/src/lmonetary.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:  Contains the source for all the system calls in libc
    15  *     
    16  *
    17 */
    18 
    19  
    20 #include <limits.h>
    21 #include <stdlib.h>
    22 #include <sys/cdefs.h>
    23 #include "localeinfo.h"
    24 #include "lmonetary.h"
    25 
    26 #if (defined(__SYMBIAN32__) && (defined(__WINSCW__) || defined(__WINS__)))
    27 #include "libc_wsd_defs.h"
    28 #endif
    29 
    30 // Muzibour : Include #include <sys/cdefs.h> and then use the macro __BEGIN_DECLS
    31 __BEGIN_DECLS
    32 extern int __mlocale_changed;
    33 #ifdef EMULATOR
    34 int *GET_WSD_VAR_NAME(__mlocale_changed, g)();
    35 #define __mlocale_changed (*GET_WSD_VAR_NAME(__mlocale_changed, g)())
    36 #endif //EMULATOR
    37 __END_DECLS
    38 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
    39 __BEGIN_DECLS
    40 extern unsigned char __clocale_set;
    41 #ifdef EMULATOR
    42 unsigned char *GET_WSD_VAR_NAME(__clocale_set, g)();
    43 #define __clocale_set (*GET_WSD_VAR_NAME(__clocale_set, g)())
    44 #endif //EMULATOR
    45 __END_DECLS
    46 #endif
    47 #ifndef EMULATOR
    48 int	_monetary_using_locale;
    49 #else //EMULATOR
    50 
    51 GET_GLOBAL_VAR_FROM_TLS(_monetary_using_locale, int)
    52 #define	_monetary_using_locale (*GET_WSD_VAR_NAME(_monetary_using_locale, g)())
    53 #endif //EMULATOR
    54 
    55 #ifndef EMULATOR
    56 static char	empty[] = "";
    57 static char	numempty[] = { CHAR_MAX, '\0'};
    58 #else //EMULATOR
    59 static const char	empty[] = "";
    60 static const char	numempty[] = { CHAR_MAX, '\0'};
    61 
    62 #endif //EMULATOR
    63 
    64 static const struct lc_monetary_T _C_monetary_locale = {
    65 	empty,		/* int_curr_symbol */
    66 	empty,		/* currency_symbol */
    67 	empty,		/* mon_decimal_point */
    68 	empty,		/* mon_thousands_sep */
    69 	numempty,	/* mon_grouping */
    70 	empty,		/* positive_sign */
    71 	empty,		/* negative_sign */
    72 	numempty,	/* int_frac_digits */
    73 	numempty,	/* frac_digits */
    74 	numempty,	/* p_cs_precedes */
    75 	numempty,	/* p_sep_by_space */
    76 	numempty,	/* n_cs_precedes */
    77 	numempty,	/* n_sep_by_space */
    78 	numempty,	/* p_sign_posn */
    79 	numempty,	/* n_sign_posn */
    80 	numempty,	/* int_p_cs_precedes */
    81 	numempty,	/* int_n_cs_precedes */
    82 	numempty,	/* int_p_sep_by_space */
    83 	numempty,	/* int_n_sep_by_space */
    84 	numempty,	/* int_p_sign_posn */
    85 	numempty	/* int_n_sign_posn */
    86 };
    87 
    88 
    89 
    90 int
    91 __monetary_load_locale(const char* localeName)
    92 {
    93 	//Get an instance of locale object
    94 	CLocale* locale = CLocale::GetInstance();	
    95 	//Load the monetary(LC_MONETARY category) information
    96 	TInt ret = KErrNone;
    97 	TRAPD(result,ret = locale->MonetaryLoadLocaleL(localeName));
    98 	if ((result != KErrNone) || (ret == -1))
    99 	{
   100 		return -1;
   101 	}
   102 	__mlocale_changed = 1;
   103 	_monetary_using_locale = 1;
   104 	
   105 	return 0;
   106 }
   107 
   108 struct lc_monetary_T *
   109 __get_current_monetary_locale(void)
   110 {
   111 	//Retreive the monetary(LC_MONETARY category) information
   112 	if(_monetary_using_locale)
   113 	{
   114 		return (CLocale::GetCurrentMonetaryLocale());			
   115 	}
   116 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
   117 	else if(__clocale_set)
   118 #endif
   119 	//return POSIX C locale monetary(LC_MONETARY category) information
   120 	return ((struct lc_monetary_T *)&_C_monetary_locale);
   121 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
   122 	else
   123 	{
   124 		CLocale *l=CLocale::GetInstance();
   125 		TRAPD(result,l->MonetaryLoadLocaleL(NULL));
   126 		if (result != KErrNone)
   127 		{
   128 			return NULL;
   129 		}
   130 		return (CLocale::GetCurrentMonetaryLocale());
   131 	}
   132 #endif
   133 }
   134 
   135 #ifdef LOCALE_DEBUG
   136 void
   137 monetdebug() {
   138 printf(	"int_curr_symbol = %s\n"
   139 	"currency_symbol = %s\n"
   140 	"mon_decimal_point = %s\n"
   141 	"mon_thousands_sep = %s\n"
   142 	"mon_grouping = %s\n"
   143 	"positive_sign = %s\n"
   144 	"negative_sign = %s\n"
   145 	"int_frac_digits = %d\n"
   146 	"frac_digits = %d\n"
   147 	"p_cs_precedes = %d\n"
   148 	"p_sep_by_space = %d\n"
   149 	"n_cs_precedes = %d\n"
   150 	"n_sep_by_space = %d\n"
   151 	"p_sign_posn = %d\n"
   152 	"n_sign_posn = %d\n",
   153 	"int_p_cs_precedes = %d\n"
   154 	"int_p_sep_by_space = %d\n"
   155 	"int_n_cs_precedes = %d\n"
   156 	"int_n_sep_by_space = %d\n"
   157 	"int_p_sign_posn = %d\n"
   158 	"int_n_sign_posn = %d\n",
   159 	_monetary_locale.int_curr_symbol,
   160 	_monetary_locale.currency_symbol,
   161 	_monetary_locale.mon_decimal_point,
   162 	_monetary_locale.mon_thousands_sep,
   163 	_monetary_locale.mon_grouping,
   164 	_monetary_locale.positive_sign,
   165 	_monetary_locale.negative_sign,
   166 	_monetary_locale.int_frac_digits[0],
   167 	_monetary_locale.frac_digits[0],
   168 	_monetary_locale.p_cs_precedes[0],
   169 	_monetary_locale.p_sep_by_space[0],
   170 	_monetary_locale.n_cs_precedes[0],
   171 	_monetary_locale.n_sep_by_space[0],
   172 	_monetary_locale.p_sign_posn[0],
   173 	_monetary_locale.n_sign_posn[0],
   174 	_monetary_locale.int_p_cs_precedes[0],
   175 	_monetary_locale.int_p_sep_by_space[0],
   176 	_monetary_locale.int_n_cs_precedes[0],
   177 	_monetary_locale.int_n_sep_by_space[0],
   178 	_monetary_locale.int_p_sign_posn[0],
   179 	_monetary_locale.int_n_sign_posn[0]
   180 );
   181 }
   182 #endif /* LOCALE_DEBUG */