os/ossrv/stdcpp/src/c_locale_libc.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
# include "stlport_prefix.h" 
sl@0
    20
#include <limits.h>
sl@0
    21
sl@0
    22
//madhu - 18/8/06
sl@0
    23
#include "locale.h"
sl@0
    24
#include "langinfo.h"
sl@0
    25
#include <string.h>
sl@0
    26
#include <stdlib.h>
sl@0
    27
#include <cwctype>
sl@0
    28
#include "c_locale.h"
sl@0
    29
#define	CODECVT_ICONV //Define CODECVT_ICONV to use ICONV APIs for code conversion.
sl@0
    30
sl@0
    31
//#define _MESSAGE_CATALOG_
sl@0
    32
#ifdef	_MESSAGE_CATALOG_
sl@0
    33
#include <libintl.h>
sl@0
    34
#endif
sl@0
    35
sl@0
    36
# ifdef _STLP_REAL_LOCALE_IMPLEMENTED
sl@0
    37
sl@0
    38
// here, we'll put C locale implementation for those compilers where
sl@0
    39
// it has to be done in C++
sl@0
    40
sl@0
    41
# else
sl@0
    42
sl@0
    43
/* This is a "stub" implementation of the "c_locale.h" interface,
sl@0
    44
   intended for operating systems where we have not yet written
sl@0
    45
   a real implementation.  A C++ library using this stub implementation
sl@0
    46
   is still standard-conforming, since the C++ standard does not require
sl@0
    47
   that any locales other than "C" be supported.
sl@0
    48
*/
sl@0
    49
sl@0
    50
#if 0 //Madhu - 18/8/06
sl@0
    51
/* Framework functions */
sl@0
    52
sl@0
    53
struct _Locale_ctype    /* { } */ ;
sl@0
    54
struct _Locale_numeric  /* { } */;
sl@0
    55
struct _Locale_time      /* { } */;
sl@0
    56
struct _Locale_collate   /*{ } */;
sl@0
    57
struct _Locale_monetary  /* { } */;
sl@0
    58
struct _Locale_messages  /* { } */;
sl@0
    59
sl@0
    60
#endif //#if 0
sl@0
    61
sl@0
    62
sl@0
    63
#ifdef CODECVT_ICONV
sl@0
    64
#include <iconv.h>
sl@0
    65
#include <errno.h>
sl@0
    66
#define	UNICODESTR	"UCS2"
sl@0
    67
struct node;
sl@0
    68
enum CONVWAY
sl@0
    69
{
sl@0
    70
	
sl@0
    71
	IN = 0,
sl@0
    72
	OUT
sl@0
    73
sl@0
    74
};
sl@0
    75
typedef struct node
sl@0
    76
{
sl@0
    77
	mbstate_t	*state;
sl@0
    78
	iconv_t		in_iconvstate;
sl@0
    79
	iconv_t		out_iconvstate;
sl@0
    80
	struct node  *next;
sl@0
    81
}StateList;
sl@0
    82
sl@0
    83
void BEtoLE(wchar_t* src, int size)
sl@0
    84
{
sl@0
    85
	int i = 0;
sl@0
    86
	
sl@0
    87
	for (i = 0;i<size;i++)
sl@0
    88
		src[i] = (src[i]>>8) | (src[i]<<8);
sl@0
    89
}
sl@0
    90
sl@0
    91
void ExtractCodeset(char* name, char* codeset)
sl@0
    92
{
sl@0
    93
	char* temp = strstr(name,".");
sl@0
    94
	if( temp != NULL)
sl@0
    95
		{
sl@0
    96
		temp++;
sl@0
    97
		while ( (*temp)&&(*temp!='=') )
sl@0
    98
		*codeset++ = *temp++;
sl@0
    99
		}
sl@0
   100
}
sl@0
   101
sl@0
   102
int AddState(StateList **list, iconv_t icnvstate, mbstate_t* state, enum CONVWAY way)
sl@0
   103
{
sl@0
   104
	StateList *temp = *list;
sl@0
   105
	StateList *newnode = NULL;
sl@0
   106
	while(temp)
sl@0
   107
	{
sl@0
   108
		if (temp->state == state)	
sl@0
   109
			break;
sl@0
   110
		temp = temp->next;
sl@0
   111
	}
sl@0
   112
	
sl@0
   113
	if (!temp)
sl@0
   114
	{		
sl@0
   115
		newnode = new StateList;
sl@0
   116
		if (newnode == NULL)
sl@0
   117
			return 0;
sl@0
   118
		newnode->next = NULL;
sl@0
   119
		newnode->state = state;
sl@0
   120
		newnode->in_iconvstate = newnode->out_iconvstate = NULL;
sl@0
   121
	}
sl@0
   122
	if(newnode)
sl@0
   123
		temp = newnode;
sl@0
   124
	if (!way)
sl@0
   125
		temp->in_iconvstate = icnvstate;
sl@0
   126
	else
sl@0
   127
		temp->out_iconvstate = icnvstate;
sl@0
   128
	
sl@0
   129
	if (*list == NULL)
sl@0
   130
	{
sl@0
   131
		*list = temp;
sl@0
   132
		return 1;	
sl@0
   133
	}
sl@0
   134
	else if(newnode)
sl@0
   135
	{
sl@0
   136
			
sl@0
   137
		StateList *move = *list;
sl@0
   138
		while(move->next)
sl@0
   139
			move = move->next;
sl@0
   140
			
sl@0
   141
		move->next = temp;
sl@0
   142
	}
sl@0
   143
	return 1;	
sl@0
   144
	
sl@0
   145
}
sl@0
   146
sl@0
   147
iconv_t	GetState(StateList *list, mbstate_t* state, enum CONVWAY way)
sl@0
   148
{
sl@0
   149
	while(list)
sl@0
   150
	{
sl@0
   151
		if (list->state == state)
sl@0
   152
		{
sl@0
   153
			if (!way)
sl@0
   154
				return (iconv_t)list->in_iconvstate;
sl@0
   155
			else
sl@0
   156
				return (iconv_t)list->out_iconvstate;
sl@0
   157
		}
sl@0
   158
			
sl@0
   159
		list = list->next;
sl@0
   160
	}
sl@0
   161
	return NULL;
sl@0
   162
}
sl@0
   163
sl@0
   164
void DeleteAllStates(StateList *list)
sl@0
   165
{	
sl@0
   166
	while(list)
sl@0
   167
	{
sl@0
   168
		StateList *temp =list ;
sl@0
   169
		iconv_close(temp->in_iconvstate);
sl@0
   170
		iconv_close(temp->out_iconvstate);
sl@0
   171
		list = list->next;
sl@0
   172
		delete temp;
sl@0
   173
	}
sl@0
   174
}
sl@0
   175
sl@0
   176
sl@0
   177
#endif
sl@0
   178
sl@0
   179
sl@0
   180
sl@0
   181
//Madhu - locale function definitions - START
sl@0
   182
//Madhu - temporarily hardcoded system default locale - 18/8/06
sl@0
   183
#define LOCALE_SYSTEM_DEFAULT	"C"
sl@0
   184
#define	MAX_NAME_LEN	64	
sl@0
   185
char	presentLocaleName[64]; // Stores present locale name.
sl@0
   186
 
sl@0
   187
sl@0
   188
sl@0
   189
#if defined (__GNUC__) || defined (_KCC) || defined(__ICC)
sl@0
   190
typedef unsigned short int _Locale_mask_t;
sl@0
   191
#else
sl@0
   192
typedef unsigned int _Locale_mask_t;
sl@0
   193
#endif
sl@0
   194
sl@0
   195
typedef struct _Locale_ctype { 
sl@0
   196
	char name[MAX_NAME_LEN];
sl@0
   197
	_Locale_mask_t	ctable[257];	
sl@0
   198
#ifdef CODECVT_ICONV
sl@0
   199
	StateList *statelist;
sl@0
   200
	~_Locale_ctype() 
sl@0
   201
	{
sl@0
   202
		DeleteAllStates(statelist);
sl@0
   203
	}
sl@0
   204
#endif
sl@0
   205
  
sl@0
   206
} L_ctype_t;
sl@0
   207
sl@0
   208
sl@0
   209
typedef struct _Locale_numeric	{  
sl@0
   210
  char name[MAX_NAME_LEN];
sl@0
   211
  char decimal_point[4];
sl@0
   212
  char thousands_sep[4];
sl@0
   213
  char *grouping;
sl@0
   214
} L_numeric_t;
sl@0
   215
sl@0
   216
typedef struct _Locale_time	{  
sl@0
   217
  char name[MAX_NAME_LEN];
sl@0
   218
  char *month[12];
sl@0
   219
  char *abbrev_month[12];
sl@0
   220
  char *dayofweek[7];
sl@0
   221
  char *abbrev_dayofweek[7];
sl@0
   222
} L_time_t;
sl@0
   223
sl@0
   224
typedef struct _Locale_collate	{
sl@0
   225
  char name[MAX_NAME_LEN];
sl@0
   226
} L_collate_t;
sl@0
   227
sl@0
   228
typedef struct _Locale_monetary	{  
sl@0
   229
  char name[MAX_NAME_LEN]; 
sl@0
   230
  char decimal_point[4];
sl@0
   231
  char thousands_sep[4];
sl@0
   232
  char *grouping;
sl@0
   233
  char int_curr_symbol[5]; // 3+1+1
sl@0
   234
  char curr_symbol[6];
sl@0
   235
  char negative_sign[5];
sl@0
   236
  char positive_sign[5];
sl@0
   237
  int frac_digits; 
sl@0
   238
  int int_frac_digits;
sl@0
   239
} L_monetary_t;
sl@0
   240
sl@0
   241
typedef struct _Locale_messages	{
sl@0
   242
  char name[MAX_NAME_LEN];
sl@0
   243
  char* domain;
sl@0
   244
} L_messages_t;
sl@0
   245
sl@0
   246
sl@0
   247
char* __getString(char* str)
sl@0
   248
{
sl@0
   249
	int len = strlen(str)+1;
sl@0
   250
	char* temp = (char*) new char[len];
sl@0
   251
	strcpy(temp, str);
sl@0
   252
	
sl@0
   253
	return temp;
sl@0
   254
	
sl@0
   255
}
sl@0
   256
sl@0
   257
/* Common function to set locale information */
sl@0
   258
#if 0
sl@0
   259
static void* Locale_Common_Create(const char* locale)
sl@0
   260
{
sl@0
   261
		
sl@0
   262
	setlocale(LC_ALL, locale);
sl@0
   263
	
sl@0
   264
	return (void*) localeconv();
sl@0
   265
	
sl@0
   266
		
sl@0
   267
}
sl@0
   268
#endif
sl@0
   269
sl@0
   270
/* Gets the system locale name */
sl@0
   271
static const char* Locale_common_default( char* name)
sl@0
   272
{
sl@0
   273
#if 0
sl@0
   274
	char* presentLocalename = NULL;
sl@0
   275
	char* defaultLocalename = NULL;
sl@0
   276
	
sl@0
   277
	//Madhu - going round to get default system locale, need to find alternative - 18/8/96
sl@0
   278
	presentLocalename = setlocale(LC_ALL, NULL);
sl@0
   279
	defaultLocalename = setlocale(LC_ALL, "");
sl@0
   280
	setlocale(LC_ALL, presentLocalename);
sl@0
   281
#endif
sl@0
   282
sl@0
   283
	if(name!=NULL)
sl@0
   284
		strcpy(name,LOCALE_SYSTEM_DEFAULT);
sl@0
   285
	
sl@0
   286
	return LOCALE_SYSTEM_DEFAULT;
sl@0
   287
	
sl@0
   288
}
sl@0
   289
sl@0
   290
#if 0
sl@0
   291
/* Gets the present locale name */ 
sl@0
   292
static char* Locale_common_name(const void* cat, char* name)
sl@0
   293
{
sl@0
   294
#if 0
sl@0
   295
	char* presentLocalename = NULL;
sl@0
   296
	
sl@0
   297
	presentLocalename = setlocale(LC_ALL, NULL);
sl@0
   298
	strcpy(name,presentLocalename);
sl@0
   299
	
sl@0
   300
	return presentLocalename;
sl@0
   301
#endif	
sl@0
   302
	L_ctype_t* locale = (L_ctype_t*) cat;
sl@0
   303
	strcpy(name,locale->name);
sl@0
   304
	return name;
sl@0
   305
}
sl@0
   306
#endif
sl@0
   307
/* */
sl@0
   308
static char * Locale_extract_name ( const char *cname, char *into, int category )
sl@0
   309
{
sl@0
   310
  int i = 0;
sl@0
   311
  const char * end;
sl@0
   312
const char* strstar = "*", *strnull = "";
sl@0
   313
  
sl@0
   314
  if ( cname[0] != '/' )
sl@0
   315
  {
sl@0
   316
  	if (strcmp(cname,strnull) == 0)
sl@0
   317
  		return strcpy(into, strstar);
sl@0
   318
  	else
sl@0
   319
  		return strcpy(into, cname); /* simple locale name */
sl@0
   320
  }
sl@0
   321
  
sl@0
   322
  for ( i = 0; i <= category; i ++ ) {
sl@0
   323
    while ( *cname != '\0' && *cname != '/' )
sl@0
   324
      cname++;
sl@0
   325
    if ( *cname == '\0' )
sl@0
   326
      return into;
sl@0
   327
    cname++;
sl@0
   328
  }
sl@0
   329
  
sl@0
   330
  if ( *cname == '\0' )
sl@0
   331
    return into;
sl@0
   332
  
sl@0
   333
  end = cname;
sl@0
   334
  while ( *end != '\0' && *end != '/' )
sl@0
   335
    end++;
sl@0
   336
  
sl@0
   337
  strncpy ( into, cname, end - cname );
sl@0
   338
  into [ end - cname ] = '\0';
sl@0
   339
  
sl@0
   340
  return into;
sl@0
   341
}
sl@0
   342
sl@0
   343
# ifdef __cplusplus
sl@0
   344
_STLP_BEGIN_NAMESPACE //Madhu - moved to here
sl@0
   345
extern "C" {
sl@0
   346
sl@0
   347
_Locale_mask_t  Get_locale_wchar_ctype(wint_t wc, _Locale_mask_t  /*mask*/)
sl@0
   348
sl@0
   349
{
sl@0
   350
	_Locale_mask_t  ret = 0;
sl@0
   351
	
sl@0
   352
	if (iswcntrl(wc))  ret |= _Locale_CNTRL;
sl@0
   353
	if (iswupper(wc))  ret |= _Locale_UPPER;
sl@0
   354
	if (iswlower(wc))  ret |= _Locale_LOWER;
sl@0
   355
	if (iswdigit(wc))  ret |= _Locale_DIGIT;
sl@0
   356
	if (iswxdigit(wc)) ret |= _Locale_XDIGIT;
sl@0
   357
	if (iswpunct(wc))  ret |= _Locale_PUNCT;
sl@0
   358
	if (iswspace(wc))  ret |= _Locale_SPACE;
sl@0
   359
	if (iswprint(wc))  ret |= _Locale_PRINT;
sl@0
   360
	if (iswalpha(wc))  ret |= _Locale_ALPHA;
sl@0
   361
	
sl@0
   362
	return ret;
sl@0
   363
  
sl@0
   364
}
sl@0
   365
sl@0
   366
_Locale_mask_t  Get_locale_char_ctype(unsigned char c)
sl@0
   367
sl@0
   368
{
sl@0
   369
	_Locale_mask_t  ret = 0;
sl@0
   370
	
sl@0
   371
	if (iscntrl(c))  ret |= _Locale_CNTRL;
sl@0
   372
	if (isupper(c))  ret |= _Locale_UPPER;
sl@0
   373
	if (islower(c))  ret |= _Locale_LOWER;
sl@0
   374
	if (isdigit(c))  ret |= _Locale_DIGIT;
sl@0
   375
	if (isxdigit(c)) ret |= _Locale_XDIGIT;
sl@0
   376
	if (ispunct(c))  ret |= _Locale_PUNCT;
sl@0
   377
	if (isspace(c))  ret |= _Locale_SPACE;
sl@0
   378
	if (isprint(c))  ret |= _Locale_PRINT;
sl@0
   379
	if (isalpha(c))  ret |= _Locale_ALPHA;
sl@0
   380
	
sl@0
   381
	return ret;
sl@0
   382
  
sl@0
   383
}
sl@0
   384
//Madhu - locale function definitions - END
sl@0
   385
sl@0
   386
sl@0
   387
//# ifdef __cplusplus
sl@0
   388
//_STLP_BEGIN_NAMESPACE
sl@0
   389
sl@0
   390
# define __DUMMY_PAR
sl@0
   391
# define __DUMMY_PAR1
sl@0
   392
# define __DUMMY_PAR2
sl@0
   393
# define __DUMMY_PAR3
sl@0
   394
# define __DUMMY_PAR4
sl@0
   395
# define __DUMMY_PAR5
sl@0
   396
# define __DUMMY_PAR6
sl@0
   397
# define __DUMMY_PAR7
sl@0
   398
# define __DUMMY_PAR8
sl@0
   399
# endif
sl@0
   400
    
sl@0
   401
 void* _Locale_ctype_create(const char * name)
sl@0
   402
 { 
sl@0
   403
 
sl@0
   404
 	unsigned char buffer[256];
sl@0
   405
	int i;
sl@0
   406
	_Locale_mask_t* ctable;
sl@0
   407
	
sl@0
   408
 	L_ctype_t *plocCType = (L_ctype_t*) new (L_ctype_t);
sl@0
   409
 	
sl@0
   410
 	if (!plocCType)
sl@0
   411
		return NULL;
sl@0
   412
 	
sl@0
   413
 	strcpy(plocCType->name, name);
sl@0
   414
	char* ptemp = setlocale(LC_CTYPE, name); 
sl@0
   415
	if (!ptemp)
sl@0
   416
		return NULL;
sl@0
   417
 	ctable = plocCType->ctable;
sl@0
   418
 	
sl@0
   419
	/* Partial implementation for ANSI code page, need to implement for DBCS code pages*/
sl@0
   420
	
sl@0
   421
	/* Make table with all characters. */
sl@0
   422
    for(i = 0; i < 256; i++) buffer[i] = i;
sl@0
   423
    
sl@0
   424
    for (i=0;i<256;i++)
sl@0
   425
    {
sl@0
   426
    	
sl@0
   427
    	ctable[i+1] = Get_locale_char_ctype(buffer[i]);	
sl@0
   428
    }	
sl@0
   429
 	ctable[0] = 0; //EOF
sl@0
   430
#ifdef CODECVT_ICONV
sl@0
   431
	plocCType->statelist = NULL;	
sl@0
   432
#endif 	
sl@0
   433
 	return plocCType;
sl@0
   434
 }
sl@0
   435
  
sl@0
   436
 void* _Locale_numeric_create(const char *name)
sl@0
   437
 { 
sl@0
   438
 	L_numeric_t *plocNumeric = (L_numeric_t *)new (L_numeric_t);
sl@0
   439
 	struct lconv *plconv;
sl@0
   440
 	
sl@0
   441
 	if (!plocNumeric)
sl@0
   442
		return NULL; 	
sl@0
   443
 	strcpy(plocNumeric->name, name);
sl@0
   444
 	
sl@0
   445
	char* ptemp = setlocale(LC_NUMERIC, name); 
sl@0
   446
	if (!ptemp)
sl@0
   447
		return NULL;
sl@0
   448
 	plconv = localeconv();
sl@0
   449
 	
sl@0
   450
 	//copy locale numeric data to local structure
sl@0
   451
 	strcpy(plocNumeric->decimal_point, plconv->decimal_point);
sl@0
   452
 	plocNumeric->grouping = __getString(plconv->grouping);
sl@0
   453
 	strcpy(plocNumeric->thousands_sep, plconv->thousands_sep);
sl@0
   454
 	
sl@0
   455
  	return plocNumeric; 
sl@0
   456
 }
sl@0
   457
 
sl@0
   458
 void*_Locale_time_create(const char * name)
sl@0
   459
 { 
sl@0
   460
 	L_time_t *plocTime = (L_time_t *)new(L_time_t);
sl@0
   461
 	//struct lconv *plconv;
sl@0
   462
 	
sl@0
   463
 	if (!plocTime )
sl@0
   464
		return NULL; 	
sl@0
   465
 	strcpy(plocTime ->name, name);
sl@0
   466
 	
sl@0
   467
	char* ptemp = setlocale(LC_TIME, name); 
sl@0
   468
	if (!ptemp)
sl@0
   469
		return NULL;
sl@0
   470
 	//plconv = localeconv();
sl@0
   471
 	
sl@0
   472
 	int i;
sl@0
   473
 	int index = (MON_1);
sl@0
   474
 	//Get all month names
sl@0
   475
 	for (i = 0;i<12;i++,index++)
sl@0
   476
 		plocTime->month[i] = __getString(nl_langinfo(index)); 	
sl@0
   477
 	
sl@0
   478
 	//Get all abbrevated month names
sl@0
   479
 	index = (ABMON_1);
sl@0
   480
 	for (i = 0;i<12;i++,index++)
sl@0
   481
 		plocTime->abbrev_month[i] = __getString(nl_langinfo(index));
sl@0
   482
 		
sl@0
   483
  	//Get all weekday names
sl@0
   484
 	index = (DAY_1);
sl@0
   485
 	for (i = 0;i<7;i++,index++)
sl@0
   486
 		plocTime->dayofweek[i] = __getString(nl_langinfo(index));
sl@0
   487
 	
sl@0
   488
  	//Get all weekday names
sl@0
   489
 	index = (ABDAY_1);
sl@0
   490
 	for (i = 0;i<7;i++,index++)
sl@0
   491
 		plocTime->abbrev_dayofweek[i] = __getString(nl_langinfo(index));
sl@0
   492
 	
sl@0
   493
  	 	
sl@0
   494
 	return plocTime;
sl@0
   495
 }
sl@0
   496
 
sl@0
   497
 void* _Locale_collate_create(const char *name)
sl@0
   498
 { 
sl@0
   499
 	L_collate_t *plocCollate = (L_collate_t *)new(L_collate_t);
sl@0
   500
 	
sl@0
   501
 	if (!plocCollate)
sl@0
   502
		return NULL; 	
sl@0
   503
 	strcpy(plocCollate->name, name);
sl@0
   504
 	
sl@0
   505
 	return plocCollate;
sl@0
   506
 }
sl@0
   507
 
sl@0
   508
 void* _Locale_monetary_create(const char * name)
sl@0
   509
 { 
sl@0
   510
 	L_monetary_t *plocMonetary = (L_monetary_t *)new(L_monetary_t);
sl@0
   511
 	struct lconv *plconv;
sl@0
   512
 	
sl@0
   513
 	if (!plocMonetary)
sl@0
   514
		return NULL; 	
sl@0
   515
 	strcpy(plocMonetary->name, name);
sl@0
   516
 	
sl@0
   517
	char* ptemp = setlocale(LC_MONETARY, name); 
sl@0
   518
	if (!ptemp)
sl@0
   519
		return NULL;
sl@0
   520
 	plconv = localeconv();
sl@0
   521
 	
sl@0
   522
 	strcpy(plocMonetary->decimal_point,plconv->mon_decimal_point);
sl@0
   523
  	strcpy(plocMonetary->thousands_sep, plconv->mon_thousands_sep);
sl@0
   524
  	plocMonetary->grouping = __getString(plconv->mon_grouping);
sl@0
   525
  	strcpy(plocMonetary->int_curr_symbol, plconv->int_curr_symbol); // 3+1+1
sl@0
   526
  	strcpy(plocMonetary->curr_symbol, plconv->currency_symbol);
sl@0
   527
  	strcpy(plocMonetary->negative_sign, plconv->negative_sign);
sl@0
   528
  	strcpy(plocMonetary->positive_sign, plconv->positive_sign);
sl@0
   529
  	plocMonetary->frac_digits = plconv->frac_digits;
sl@0
   530
  	plocMonetary->int_frac_digits = plconv->int_frac_digits;
sl@0
   531
 	
sl@0
   532
 	return plocMonetary;
sl@0
   533
 }
sl@0
   534
 void* _Locale_messages_create(const char *name)
sl@0
   535
 { 
sl@0
   536
 	L_messages_t *plocMessages= (L_messages_t *)new(L_messages_t);
sl@0
   537
 	
sl@0
   538
 	if (!plocMessages)
sl@0
   539
		return NULL; 	
sl@0
   540
 	strcpy(plocMessages->name, name);
sl@0
   541
 	
sl@0
   542
 	return plocMessages;
sl@0
   543
 }
sl@0
   544
sl@0
   545
 const char* _Locale_ctype_default(char* buff)
sl@0
   546
 { 
sl@0
   547
 	return Locale_common_default(buff);
sl@0
   548
 }
sl@0
   549
 
sl@0
   550
 const char* _Locale_numeric_default(char *buff)
sl@0
   551
 { 
sl@0
   552
 	return Locale_common_default(buff);
sl@0
   553
 }
sl@0
   554
 
sl@0
   555
 const char* _Locale_time_default(char* buff)
sl@0
   556
 { 
sl@0
   557
 	return Locale_common_default(buff);
sl@0
   558
 }
sl@0
   559
 
sl@0
   560
 const char* _Locale_collate_default(char* buff)
sl@0
   561
 { 
sl@0
   562
 	return Locale_common_default(buff); 
sl@0
   563
 }
sl@0
   564
 
sl@0
   565
 const char* _Locale_monetary_default(char* buff)
sl@0
   566
 { 
sl@0
   567
 	return Locale_common_default(buff);
sl@0
   568
 }
sl@0
   569
 
sl@0
   570
 const char* _Locale_messages_default(char* buff) 
sl@0
   571
 { 
sl@0
   572
 	return Locale_common_default(buff);
sl@0
   573
 }
sl@0
   574
sl@0
   575
 char* _Locale_ctype_name(const void* cat, char* buff)
sl@0
   576
 { 
sl@0
   577
 	L_ctype_t* locale = (L_ctype_t*) cat;
sl@0
   578
	strcpy(buff,locale->name);
sl@0
   579
	return buff;
sl@0
   580
 	//return Locale_common_name(locale,buff);
sl@0
   581
 }
sl@0
   582
 
sl@0
   583
 char* _Locale_numeric_name(const void* cat, char* buff)
sl@0
   584
 { 
sl@0
   585
 	L_numeric_t* locale = (L_numeric_t*) cat;
sl@0
   586
	strcpy(buff,locale->name);
sl@0
   587
	return buff;
sl@0
   588
 	//return Locale_common_name(locale,buff);
sl@0
   589
 }
sl@0
   590
 
sl@0
   591
 char* _Locale_time_name(const void* cat, char* buff)
sl@0
   592
 { 
sl@0
   593
 	L_time_t* locale = (L_time_t*) cat;
sl@0
   594
	strcpy(buff,locale->name);
sl@0
   595
	return buff;
sl@0
   596
 	//return Locale_common_name(locale,buff);
sl@0
   597
 }
sl@0
   598
 
sl@0
   599
 char* _Locale_collate_name(const void* cat, char* buff)
sl@0
   600
 { 
sl@0
   601
 	L_collate_t* locale = (L_collate_t*) cat;
sl@0
   602
	strcpy(buff,locale->name);
sl@0
   603
	return buff;
sl@0
   604
 	//return Locale_common_name(locale,buff);
sl@0
   605
 }
sl@0
   606
 
sl@0
   607
 char* _Locale_monetary_name(const void* cat, char* buff)
sl@0
   608
 { 
sl@0
   609
 	L_monetary_t* locale = (L_monetary_t*) cat;
sl@0
   610
	strcpy(buff,locale->name);
sl@0
   611
	return buff;
sl@0
   612
 	//return Locale_common_name(locale,buff);
sl@0
   613
 }
sl@0
   614
 
sl@0
   615
 char* _Locale_messages_name(const void* cat, char* buff)
sl@0
   616
 { 
sl@0
   617
 	L_messages_t* locale = (L_messages_t*) cat;
sl@0
   618
	strcpy(buff,locale->name);
sl@0
   619
	return buff;
sl@0
   620
 	//return Locale_common_name(locale,buff);
sl@0
   621
 }
sl@0
   622
sl@0
   623
 void _Locale_ctype_destroy(void* locale)
sl@0
   624
 {
sl@0
   625
 #ifdef	CODECVT_ICONV
sl@0
   626
 	DeleteAllStates(((L_ctype_t*)locale)->statelist);
sl@0
   627
#endif 	
sl@0
   628
 	delete((L_ctype_t*)locale);
sl@0
   629
 }
sl@0
   630
 
sl@0
   631
 void _Locale_numeric_destroy(void* locale)
sl@0
   632
 {
sl@0
   633
 	delete ((L_numeric_t*)locale)->grouping;
sl@0
   634
 	delete (L_numeric_t*)locale;
sl@0
   635
 }
sl@0
   636
 
sl@0
   637
 void _Locale_time_destroy(void* locale)
sl@0
   638
 {
sl@0
   639
 	int i;
sl@0
   640
 	L_time_t* plocTime =(L_time_t*)locale; 
sl@0
   641
 	//delete months
sl@0
   642
 	for (i = 0;i<12;i++)
sl@0
   643
 		delete (plocTime->month[i]);
sl@0
   644
 	//delete abbrevated months
sl@0
   645
 	for (i = 0;i<12;i++)
sl@0
   646
 		delete (plocTime->abbrev_month[i]);
sl@0
   647
 	//delete week day
sl@0
   648
 	for (i = 0;i<7;i++)
sl@0
   649
 		delete (plocTime->dayofweek[i]);
sl@0
   650
 	//delete abbrevated week day
sl@0
   651
 	for (i = 0;i<7;i++)
sl@0
   652
 		delete (plocTime->abbrev_dayofweek[i]);
sl@0
   653
 	 		
sl@0
   654
 	delete((L_time_t*)locale);
sl@0
   655
 }
sl@0
   656
 
sl@0
   657
 void _Locale_collate_destroy(void* locale)
sl@0
   658
 {
sl@0
   659
 	delete((L_collate_t*)locale);
sl@0
   660
 }
sl@0
   661
 
sl@0
   662
 void _Locale_monetary_destroy(void* locale)
sl@0
   663
 {
sl@0
   664
 	delete ((L_monetary_t*)locale)->grouping;
sl@0
   665
 	delete((L_monetary_t*)locale);
sl@0
   666
 }
sl@0
   667
 
sl@0
   668
 void _Locale_messages_destroy(void* locale)
sl@0
   669
 {
sl@0
   670
 	delete((L_messages_t*)locale);
sl@0
   671
 }
sl@0
   672
sl@0
   673
 char* _Locale_extract_ctype_name(const char* cname, char* buf) 
sl@0
   674
 { 
sl@0
   675
 	return Locale_extract_name(cname, buf, LC_CTYPE);
sl@0
   676
 }
sl@0
   677
 
sl@0
   678
 char* _Locale_extract_numeric_name(const char* cname, char* buf) 
sl@0
   679
 { 
sl@0
   680
 	return Locale_extract_name(cname, buf, LC_NUMERIC);
sl@0
   681
 }
sl@0
   682
 
sl@0
   683
 char* _Locale_extract_time_name(const char* cname, char* buf) 
sl@0
   684
 { 
sl@0
   685
 	return Locale_extract_name(cname, buf, LC_TIME);
sl@0
   686
 }
sl@0
   687
 
sl@0
   688
 char* _Locale_extract_collate_name(const char* cname, char* buf) 
sl@0
   689
 { 
sl@0
   690
 	return Locale_extract_name(cname, buf, LC_COLLATE); 
sl@0
   691
 }
sl@0
   692
 
sl@0
   693
 char* _Locale_extract_monetary_name(const char* cname, char* buf) 
sl@0
   694
 { 
sl@0
   695
 	return Locale_extract_name(cname, buf, LC_MONETARY);
sl@0
   696
 }
sl@0
   697
 
sl@0
   698
 char* _Locale_extract_messages_name(const char* cname, char* buf) 
sl@0
   699
 { 
sl@0
   700
 	return Locale_extract_name(cname, buf, LC_MESSAGES);
sl@0
   701
 }
sl@0
   702
sl@0
   703
 char* _Locale_compose_name(char* buf,
sl@0
   704
			     const char* ctype, const char* numeric,
sl@0
   705
			     const char* time, const char* collate,
sl@0
   706
			     const char* monetary, const char* messages,
sl@0
   707
			     const char* /*default_name*/)
sl@0
   708
 { 
sl@0
   709
 
sl@0
   710
 	if ( !strcmp ( ctype, numeric ) &&
sl@0
   711
	 !strcmp ( ctype, time ) &&
sl@0
   712
	 !strcmp ( ctype, collate ) &&
sl@0
   713
	 !strcmp ( ctype, monetary ) &&
sl@0
   714
	 !strcmp ( ctype, messages ) )
sl@0
   715
	return strcpy ( buf, ctype );
sl@0
   716
sl@0
   717
    strcpy ( buf, "/" );
sl@0
   718
    strcat ( buf, ctype );
sl@0
   719
sl@0
   720
    strcat ( buf, "/" );
sl@0
   721
    strcat ( buf, numeric );
sl@0
   722
sl@0
   723
    strcat ( buf, "/" );
sl@0
   724
    strcat ( buf, time );
sl@0
   725
sl@0
   726
    strcat ( buf, "/" );
sl@0
   727
    strcat ( buf, collate );
sl@0
   728
sl@0
   729
    strcat ( buf, "/" );
sl@0
   730
    strcat ( buf, monetary );
sl@0
   731
sl@0
   732
    strcat ( buf, "/" );
sl@0
   733
    strcat ( buf, messages );
sl@0
   734
sl@0
   735
    return buf;
sl@0
   736
 }
sl@0
   737
sl@0
   738
sl@0
   739
/* ctype */
sl@0
   740
sl@0
   741
const  _Locale_mask_t* _Locale_ctype_table(struct _Locale_ctype* lctype)
sl@0
   742
{ 
sl@0
   743
	    
sl@0
   744
	return lctype->ctable; 
sl@0
   745
}
sl@0
   746
sl@0
   747
int _Locale_toupper(struct _Locale_ctype* /*lctype*/, int c)
sl@0
   748
{ 
sl@0
   749
	return toupper(c); 
sl@0
   750
}
sl@0
   751
sl@0
   752
int _Locale_tolower(L_ctype_t* /*lctype*/, int c) 
sl@0
   753
{ 
sl@0
   754
	return tolower(c); 
sl@0
   755
}
sl@0
   756
sl@0
   757
#ifndef _STLP_NO_WCHAR_T
sl@0
   758
sl@0
   759
 _Locale_mask_t  _Locale_wchar_ctype(L_ctype_t* /*lctype*/, wint_t c, _Locale_mask_t  which_bits)
sl@0
   760
 { 
sl@0
   761
 	_Locale_mask_t mask = Get_locale_wchar_ctype(c,which_bits);
sl@0
   762
 	
sl@0
   763
 	return mask & which_bits; 
sl@0
   764
 }
sl@0
   765
 
sl@0
   766
 wint_t _Locale_wchar_tolower(L_ctype_t* lctype, wint_t c)
sl@0
   767
 { 
sl@0
   768
 	setlocale(LC_CTYPE, lctype->name);
sl@0
   769
 	return towlower(c); 
sl@0
   770
 }
sl@0
   771
 
sl@0
   772
 wint_t _Locale_wchar_toupper(L_ctype_t* /*lctype*/, wint_t c)
sl@0
   773
 { 
sl@0
   774
 	return towupper(c); 
sl@0
   775
 }
sl@0
   776
 
sl@0
   777
# endif
sl@0
   778
sl@0
   779
# ifndef _STLP_NO_MBSTATE_T
sl@0
   780
sl@0
   781
int _Locale_mb_cur_max (L_ctype_t * /*lctype*/) 
sl@0
   782
{ 
sl@0
   783
	return MB_CUR_MAX;
sl@0
   784
}
sl@0
   785
sl@0
   786
int _Locale_mb_cur_min (L_ctype_t * /*lctype*/) 
sl@0
   787
{ 
sl@0
   788
	return 1; 
sl@0
   789
}
sl@0
   790
sl@0
   791
int _Locale_is_stateless (L_ctype_t * /*lctype*/) 
sl@0
   792
{ 
sl@0
   793
	return (MB_CUR_MAX == 1)?1:0; 
sl@0
   794
}
sl@0
   795
sl@0
   796
#ifndef _STLP_NO_WCHAR_T
sl@0
   797
wint_t _Locale_btowc(L_ctype_t * lctype, int c) 
sl@0
   798
{ 
sl@0
   799
	setlocale(LC_CTYPE, lctype->name);
sl@0
   800
	return btowc(c); 
sl@0
   801
}
sl@0
   802
sl@0
   803
int _Locale_wctob(L_ctype_t * lctype, wint_t wc) 
sl@0
   804
{ 
sl@0
   805
	setlocale(LC_CTYPE, lctype->name);
sl@0
   806
	return wctob(wc); 
sl@0
   807
}
sl@0
   808
sl@0
   809
size_t _Locale_mbtowc(L_ctype_t *lctype,
sl@0
   810
                                 wchar_t *to, size_t n1,
sl@0
   811
                                 const char *from, size_t n, int* chars_write,
sl@0
   812
                                 mbstate_t * shift_state) 
sl@0
   813
{
sl@0
   814
#ifdef CODECVT_ICONV
sl@0
   815
	char	codeset[64] = 
sl@0
   816
	{
sl@0
   817
		0
sl@0
   818
	};
sl@0
   819
	iconv_t state = GetState(lctype->statelist, shift_state, IN);
sl@0
   820
	if (state == NULL)
sl@0
   821
	{
sl@0
   822
			ExtractCodeset(lctype->name, codeset);
sl@0
   823
			state= iconv_open(UNICODESTR,codeset);
sl@0
   824
			if (state==NULL)
sl@0
   825
				return (size_t)-1;
sl@0
   826
			if (AddState(&lctype->statelist,state,shift_state,IN) == 0)
sl@0
   827
				return (size_t)-1;
sl@0
   828
					
sl@0
   829
	}
sl@0
   830
	char* outbuf = (char*)to;
sl@0
   831
	const char* inbuf = (char*)from;
sl@0
   832
	unsigned int inbytes = n;
sl@0
   833
	unsigned int outbytes = n1*sizeof(wchar_t);
sl@0
   834
	unsigned int chars_read = iconv((void*)state,&inbuf,&inbytes,&outbuf,&outbytes);
sl@0
   835
	*chars_write = (wchar_t*)outbuf - to; 
sl@0
   836
	if (chars_read == (size_t)-1)
sl@0
   837
	{
sl@0
   838
		if ( (errno == EINVAL) || (outbuf!=(char*)to) )
sl@0
   839
		{
sl@0
   840
			BEtoLE(to,(wchar_t*)outbuf-to);
sl@0
   841
			return inbuf-from;
sl@0
   842
		}			
sl@0
   843
		
sl@0
   844
		return (size_t)-1;	
sl@0
   845
		 
sl@0
   846
	}
sl@0
   847
	BEtoLE(to,(wchar_t*)outbuf-to);
sl@0
   848
	//return (wchar_t*)outbuf-to;
sl@0
   849
	return inbuf-from;
sl@0
   850
sl@0
   851
#else
sl@0
   852
	setlocale(LC_CTYPE, lctype->name);
sl@0
   853
  return (size_t) mbtowc(to, from,n); 
sl@0
   854
#endif
sl@0
   855
}
sl@0
   856
sl@0
   857
size_t _Locale_wctomb(L_ctype_t* lctype,
sl@0
   858
                                 char *to, size_t n,
sl@0
   859
                                 const wchar_t c,
sl@0
   860
                                 mbstate_t *shift_state) 
sl@0
   861
{
sl@0
   862
#ifdef CODECVT_ICONV
sl@0
   863
  	char	codeset[64] = 
sl@0
   864
	{
sl@0
   865
		0
sl@0
   866
	};
sl@0
   867
	iconv_t state = GetState(lctype->statelist, shift_state,OUT);
sl@0
   868
	if (state == NULL)
sl@0
   869
	{
sl@0
   870
			ExtractCodeset(lctype->name, codeset);
sl@0
   871
			state= iconv_open(codeset, UNICODESTR);
sl@0
   872
			if (state==NULL)
sl@0
   873
				return (size_t)-1;
sl@0
   874
			if (AddState(&lctype->statelist,state,shift_state,OUT) == 0)
sl@0
   875
				return (size_t)-1;
sl@0
   876
					
sl@0
   877
	}
sl@0
   878
	char* outbuf = to;
sl@0
   879
	const char* inbuf = (char*)&c;
sl@0
   880
	unsigned int inbytes = 2;
sl@0
   881
	unsigned int outbytes = n;
sl@0
   882
	unsigned int chars_read = iconv((void*)state,&inbuf,&inbytes,&outbuf,&outbytes);
sl@0
   883
	if (chars_read == (size_t)-1)
sl@0
   884
	{
sl@0
   885
		if (errno == EINVAL)
sl@0
   886
			return outbuf-to;
sl@0
   887
		else
sl@0
   888
			return (size_t)-1;	
sl@0
   889
		
sl@0
   890
	}
sl@0
   891
	//BEtoLE(to,(wchar_t*)outbuf-to);
sl@0
   892
	return outbuf-to;
sl@0
   893
#else
sl@0
   894
	setlocale(LC_CTYPE, lctype->name);
sl@0
   895
  	return (size_t) wctomb(to, c);
sl@0
   896
sl@0
   897
#endif
sl@0
   898
}
sl@0
   899
sl@0
   900
# endif
sl@0
   901
sl@0
   902
//Madhu - Need to double check the implementation. 
sl@0
   903
size_t _Locale_unshift(L_ctype_t * /*lctype*/,
sl@0
   904
                                  mbstate_t *st,
sl@0
   905
                                  char *buff, size_t n, char ** next) 
sl@0
   906
{
sl@0
   907
#if 0	
sl@0
   908
    if(*st == 0)
sl@0
   909
    {
sl@0
   910
		*next = buff;
sl@0
   911
		return 0;
sl@0
   912
    }
sl@0
   913
    else
sl@0
   914
    {
sl@0
   915
		if(n < 1) 
sl@0
   916
		{ 
sl@0
   917
			*next = buff; 
sl@0
   918
			return (size_t)-2; 
sl@0
   919
		}
sl@0
   920
sl@0
   921
		*next = buff + 1;
sl@0
   922
		return 1;
sl@0
   923
    }
sl@0
   924
#endif
sl@0
   925
//Conversion is not required, because iconv will not do partial conversion.
sl@0
   926
	*next = buff;
sl@0
   927
	return 0;
sl@0
   928
}
sl@0
   929
sl@0
   930
# endif /*  _STLP_NO_MBSTATE_T */
sl@0
   931
sl@0
   932
sl@0
   933
/* Collate */
sl@0
   934
 int _Locale_strcmp(L_collate_t* lcol,
sl@0
   935
                    const char* pStr1, size_t len1, const char* pStr2,
sl@0
   936
                    size_t len2) 
sl@0
   937
{
sl@0
   938
sl@0
   939
	char *ptempStr1, *ptempStr2;
sl@0
   940
	int tempLen1,tempLen2;
sl@0
   941
sl@0
   942
	tempLen1 = _Locale_strxfrm(lcol, NULL,0,pStr1,len1);
sl@0
   943
	tempLen2 = _Locale_strxfrm(lcol, NULL,0,pStr2,len2);
sl@0
   944
	ptempStr1 = (char*) new char[tempLen1];
sl@0
   945
	ptempStr2 = (char*) new char[tempLen2];
sl@0
   946
	int ret;
sl@0
   947
	int minN = tempLen1 < tempLen2 ? tempLen1 : tempLen2;	
sl@0
   948
	setlocale(LC_COLLATE, lcol->name);
sl@0
   949
	_Locale_strxfrm(lcol, ptempStr1,tempLen1,pStr1,len1);
sl@0
   950
	_Locale_strxfrm(lcol, ptempStr2,tempLen2,pStr2,len2);
sl@0
   951
	ret = strncmp(ptempStr1, ptempStr2, minN);
sl@0
   952
	if (ret == 0) 
sl@0
   953
	{
sl@0
   954
		if (len1 < len2) 
sl@0
   955
			return -1;
sl@0
   956
		else if (len1 > len2) 
sl@0
   957
			return 1;
sl@0
   958
		else 
sl@0
   959
			return 0;
sl@0
   960
	} else
sl@0
   961
		return ret;
sl@0
   962
sl@0
   963
}
sl@0
   964
sl@0
   965
# ifndef _STLP_NO_WCHAR_T
sl@0
   966
sl@0
   967
 int _Locale_strwcmp(L_collate_t* lcol,
sl@0
   968
                     const wchar_t* pStr1, size_t len1,
sl@0
   969
                     const wchar_t* pStr2, size_t len2) 
sl@0
   970
{
sl@0
   971
	wchar_t *ptempStr1, *ptempStr2;
sl@0
   972
	int tempLen1,tempLen2;
sl@0
   973
sl@0
   974
	tempLen1 = _Locale_strwxfrm(lcol, NULL,0,pStr1,len1);
sl@0
   975
	tempLen2 = _Locale_strwxfrm(lcol, NULL,0,pStr2,len2);
sl@0
   976
	ptempStr1 = (wchar_t*) new wchar_t[tempLen1+1];
sl@0
   977
	ptempStr2 = (wchar_t*) new wchar_t[tempLen2+1];
sl@0
   978
	int ret;
sl@0
   979
	int minN = tempLen1 < tempLen2 ? tempLen1 : tempLen2;
sl@0
   980
	setlocale(LC_COLLATE, lcol->name);
sl@0
   981
	_Locale_strwxfrm(lcol, ptempStr1,tempLen1,pStr1,len1);
sl@0
   982
	_Locale_strwxfrm(lcol, ptempStr2,tempLen2,pStr2,len2);
sl@0
   983
	ret = wcsncmp(ptempStr1, ptempStr2, minN);
sl@0
   984
	if (ret == 0) 
sl@0
   985
	{
sl@0
   986
		if (len1 < len2) 
sl@0
   987
			return -1;
sl@0
   988
		else if (len1 > len2) 
sl@0
   989
			return 1;
sl@0
   990
		else 
sl@0
   991
			return 0;
sl@0
   992
	} else
sl@0
   993
		return ret;
sl@0
   994
sl@0
   995
	
sl@0
   996
}
sl@0
   997
sl@0
   998
# endif
sl@0
   999
sl@0
  1000
 size_t _Locale_strxfrm(L_collate_t* lcol,
sl@0
  1001
                        char* pDestStr, size_t destLen,
sl@0
  1002
                        const char* pSrcStr, size_t srcLen) 
sl@0
  1003
{
sl@0
  1004
	size_t n;
sl@0
  1005
	setlocale(LC_COLLATE, lcol->name);
sl@0
  1006
sl@0
  1007
	char* ptemp = (char*) new char[srcLen+1];
sl@0
  1008
	if(ptemp == NULL)
sl@0
  1009
		return 0;
sl@0
  1010
	memmove(ptemp,pSrcStr,srcLen);
sl@0
  1011
	*(ptemp+srcLen) = 0;
sl@0
  1012
	
sl@0
  1013
	n = strxfrm(pDestStr, ptemp, destLen);
sl@0
  1014
	
sl@0
  1015
	delete []ptemp;
sl@0
  1016
	
sl@0
  1017
	if ((pDestStr == NULL) || (destLen ==0) )
sl@0
  1018
		return n;
sl@0
  1019
	else if(n > destLen)
sl@0
  1020
		return (size_t)-1;
sl@0
  1021
	
sl@0
  1022
	pDestStr[n] = 0;
sl@0
  1023
	return n;
sl@0
  1024
}
sl@0
  1025
sl@0
  1026
# ifndef _STLP_NO_WCHAR_T
sl@0
  1027
sl@0
  1028
  size_t _Locale_strwxfrm(L_collate_t* lcol,
sl@0
  1029
                          wchar_t* pDestStr, size_t destLen,
sl@0
  1030
                          const wchar_t* pSrcStr, size_t srcLen)
sl@0
  1031
{
sl@0
  1032
	size_t n;
sl@0
  1033
	setlocale(LC_COLLATE, lcol->name);
sl@0
  1034
	wchar_t* ptemp = (wchar_t*) new wchar_t[srcLen+1];
sl@0
  1035
	if(ptemp == NULL)
sl@0
  1036
		return 0;
sl@0
  1037
	memmove(ptemp,pSrcStr,srcLen*sizeof(wchar_t));
sl@0
  1038
	*(ptemp+srcLen) = 0;
sl@0
  1039
	n = wcsxfrm(pDestStr, ptemp, destLen);
sl@0
  1040
	
sl@0
  1041
	delete []ptemp;
sl@0
  1042
	if ((pDestStr == NULL) || (destLen ==0) )
sl@0
  1043
		return n;
sl@0
  1044
	else if(n > destLen)
sl@0
  1045
		return (size_t)-1;
sl@0
  1046
	
sl@0
  1047
	pDestStr[n] = 0;
sl@0
  1048
	return n;
sl@0
  1049
}
sl@0
  1050
sl@0
  1051
# endif
sl@0
  1052
sl@0
  1053
/* Numeric */
sl@0
  1054
  
sl@0
  1055
 char _Locale_decimal_point(L_numeric_t* lnum)
sl@0
  1056
 { 
sl@0
  1057
 	
sl@0
  1058
 	return lnum->decimal_point[0];
sl@0
  1059
 }
sl@0
  1060
 
sl@0
  1061
 char _Locale_thousands_sep(L_numeric_t* lnum) 
sl@0
  1062
 { 
sl@0
  1063
 	 	
sl@0
  1064
 	return lnum->thousands_sep[0]; 
sl@0
  1065
 }
sl@0
  1066
 const char* _Locale_grouping(L_numeric_t*lnum) 
sl@0
  1067
 { 
sl@0
  1068
 	 	
sl@0
  1069
 	return lnum->grouping;
sl@0
  1070
 }
sl@0
  1071
sl@0
  1072
 const char * _Locale_true(L_numeric_t * /*lnum*/)  
sl@0
  1073
 { 
sl@0
  1074
 	const char* __true_name="true"; //glib and NT doing the same
sl@0
  1075
  	
sl@0
  1076
	
sl@0
  1077
 	return __true_name; 
sl@0
  1078
 }
sl@0
  1079
 
sl@0
  1080
 const char * _Locale_false(L_numeric_t * /*lnum*/) 
sl@0
  1081
 {
sl@0
  1082
 	const char* __false_name="false"; //glib and NT doing the same
sl@0
  1083
 	
sl@0
  1084
 	return __false_name;
sl@0
  1085
 }
sl@0
  1086
sl@0
  1087
sl@0
  1088
/* Monetary */
sl@0
  1089
sl@0
  1090
 const char* _Locale_int_curr_symbol(L_monetary_t * lmon)
sl@0
  1091
 { 
sl@0
  1092
 	 	
sl@0
  1093
 	return lmon->int_curr_symbol;
sl@0
  1094
 }
sl@0
  1095
 
sl@0
  1096
 const char* _Locale_currency_symbol(L_monetary_t * lmon)
sl@0
  1097
 { 
sl@0
  1098
 	 	
sl@0
  1099
 	return lmon->curr_symbol;
sl@0
  1100
 }
sl@0
  1101
 
sl@0
  1102
 char   _Locale_mon_decimal_point(L_monetary_t * lmon)
sl@0
  1103
 { 
sl@0
  1104
 	return lmon->decimal_point[0];
sl@0
  1105
 }
sl@0
  1106
 
sl@0
  1107
 char    _Locale_mon_thousands_sep(L_monetary_t * lmon)
sl@0
  1108
 { 
sl@0
  1109
 	 	
sl@0
  1110
 	return lmon->thousands_sep[0];
sl@0
  1111
 }
sl@0
  1112
 
sl@0
  1113
 const char* _Locale_mon_grouping(L_monetary_t * lmon)
sl@0
  1114
 { 
sl@0
  1115
 	 	
sl@0
  1116
 	return lmon->grouping;
sl@0
  1117
 }
sl@0
  1118
 
sl@0
  1119
 const char* _Locale_positive_sign(L_monetary_t * lmon)
sl@0
  1120
 { 
sl@0
  1121
 	 	
sl@0
  1122
 	return lmon->positive_sign;
sl@0
  1123
 }
sl@0
  1124
 
sl@0
  1125
 const char* _Locale_negative_sign(L_monetary_t * lmon)
sl@0
  1126
 { 
sl@0
  1127
 	 	
sl@0
  1128
 	return lmon->negative_sign;
sl@0
  1129
 }
sl@0
  1130
 
sl@0
  1131
 char   _Locale_int_frac_digits(L_monetary_t * lmon)
sl@0
  1132
 { 
sl@0
  1133
 	 	
sl@0
  1134
 	return lmon->int_frac_digits;
sl@0
  1135
 }
sl@0
  1136
 
sl@0
  1137
 char        _Locale_frac_digits(L_monetary_t * lmon)
sl@0
  1138
 { 
sl@0
  1139
 	 	
sl@0
  1140
 	return lmon->frac_digits;
sl@0
  1141
 }
sl@0
  1142
 
sl@0
  1143
 int         _Locale_p_cs_precedes(L_monetary_t * lmon)
sl@0
  1144
 { 
sl@0
  1145
 	struct lconv* plconv;
sl@0
  1146
 	setlocale(LC_MONETARY, lmon->name);
sl@0
  1147
 	plconv = localeconv();
sl@0
  1148
 	 	
sl@0
  1149
 	return plconv->p_cs_precedes;
sl@0
  1150
 }
sl@0
  1151
 
sl@0
  1152
 int         _Locale_p_sep_by_space(L_monetary_t * lmon)
sl@0
  1153
 { 
sl@0
  1154
 	struct lconv* plconv;
sl@0
  1155
 	setlocale(LC_MONETARY, lmon->name);
sl@0
  1156
 	plconv = localeconv();
sl@0
  1157
 		 	
sl@0
  1158
 	return plconv->p_sep_by_space;
sl@0
  1159
 }
sl@0
  1160
 
sl@0
  1161
 int         _Locale_p_sign_posn(L_monetary_t * lmon)
sl@0
  1162
 { 
sl@0
  1163
	struct lconv* plconv;
sl@0
  1164
 	setlocale(LC_MONETARY, lmon->name);
sl@0
  1165
 	plconv = localeconv();
sl@0
  1166
 	 	 	
sl@0
  1167
 	return plconv->p_sign_posn;
sl@0
  1168
 }
sl@0
  1169
 
sl@0
  1170
 int         _Locale_n_cs_precedes(L_monetary_t * lmon)
sl@0
  1171
 { 
sl@0
  1172
	struct lconv* plconv;
sl@0
  1173
 	setlocale(LC_MONETARY, lmon->name);
sl@0
  1174
 	plconv = localeconv();
sl@0
  1175
 	
sl@0
  1176
 	return plconv->n_cs_precedes;
sl@0
  1177
 }
sl@0
  1178
 
sl@0
  1179
 int          _Locale_n_sep_by_space(L_monetary_t * lmon)
sl@0
  1180
 { 
sl@0
  1181
	struct lconv* plconv;
sl@0
  1182
 	setlocale(LC_MONETARY, lmon->name);
sl@0
  1183
 	plconv = localeconv();
sl@0
  1184
 	 	 	 	
sl@0
  1185
 	return plconv->n_sep_by_space; 
sl@0
  1186
 }
sl@0
  1187
 
sl@0
  1188
 int          _Locale_n_sign_posn(L_monetary_t * lmon)
sl@0
  1189
 { 
sl@0
  1190
 	struct lconv* plconv;
sl@0
  1191
 	setlocale(LC_MONETARY, lmon->name);
sl@0
  1192
 	plconv = localeconv();
sl@0
  1193
 	
sl@0
  1194
 	return plconv->n_sign_posn; 
sl@0
  1195
 }
sl@0
  1196
sl@0
  1197
sl@0
  1198
/* Time */
sl@0
  1199
 const char * _Locale_full_monthname(L_time_t * ltime, int month)
sl@0
  1200
 { 
sl@0
  1201
 	 	
sl@0
  1202
 	return ltime->month[month];
sl@0
  1203
 }
sl@0
  1204
 
sl@0
  1205
 const char * _Locale_abbrev_monthname(L_time_t * ltime, int month)
sl@0
  1206
 { 
sl@0
  1207
 	 	
sl@0
  1208
 	return ltime->abbrev_month[month];
sl@0
  1209
 }
sl@0
  1210
 
sl@0
  1211
 const char * _Locale_full_dayofweek(L_time_t * ltime, int day)
sl@0
  1212
 { 
sl@0
  1213
 	 	
sl@0
  1214
 	return ltime->dayofweek[day];
sl@0
  1215
 }
sl@0
  1216
 
sl@0
  1217
 const char * _Locale_abbrev_dayofweek(L_time_t * ltime, int day)
sl@0
  1218
 { 
sl@0
  1219
 	 	
sl@0
  1220
 	return ltime->abbrev_dayofweek[day];
sl@0
  1221
 }
sl@0
  1222
sl@0
  1223
 const char* _Locale_d_t_fmt(L_time_t* ltime)    
sl@0
  1224
 { 
sl@0
  1225
 	setlocale(LC_TIME, ltime->name);
sl@0
  1226
 	return nl_langinfo(D_T_FMT);
sl@0
  1227
 }
sl@0
  1228
 
sl@0
  1229
 const char* _Locale_d_fmt(L_time_t* ltime)
sl@0
  1230
 {
sl@0
  1231
 	setlocale(LC_TIME, ltime->name); 
sl@0
  1232
	return nl_langinfo(D_FMT);
sl@0
  1233
 }
sl@0
  1234
 
sl@0
  1235
 const char* _Locale_t_fmt(L_time_t* ltime)
sl@0
  1236
 { 
sl@0
  1237
 	setlocale(LC_TIME, ltime->name);
sl@0
  1238
 	return nl_langinfo(T_FMT);
sl@0
  1239
 }
sl@0
  1240
 
sl@0
  1241
 const char* _Locale_long_d_t_fmt(L_time_t* ltime)
sl@0
  1242
 { 
sl@0
  1243
 	setlocale(LC_TIME, ltime->name);
sl@0
  1244
 	return nl_langinfo(D_T_FMT); //Madhu--now same as D_T_FMT, need to check
sl@0
  1245
 }
sl@0
  1246
 
sl@0
  1247
const char* _Locale_long_d_fmt(L_time_t* ltime)
sl@0
  1248
{ 
sl@0
  1249
	setlocale(LC_TIME, ltime->name);
sl@0
  1250
	return nl_langinfo(D_FMT); //Madhu--now same as D_FMT, need to check
sl@0
  1251
}
sl@0
  1252
const char* _Locale_am_str(L_time_t* ltime)     
sl@0
  1253
{ 
sl@0
  1254
	setlocale(LC_TIME, ltime->name);
sl@0
  1255
	return nl_langinfo(AM_STR);
sl@0
  1256
}
sl@0
  1257
sl@0
  1258
const char* _Locale_pm_str(L_time_t* ltime)     
sl@0
  1259
{ 
sl@0
  1260
	setlocale(LC_TIME, ltime->name);
sl@0
  1261
	return nl_langinfo(PM_STR);
sl@0
  1262
}
sl@0
  1263
sl@0
  1264
const char* _Locale_t_fmt_ampm(L_time_t* ltime) 
sl@0
  1265
{ 
sl@0
  1266
	setlocale(LC_TIME, ltime->name);
sl@0
  1267
	return nl_langinfo(T_FMT_AMPM);
sl@0
  1268
}
sl@0
  1269
sl@0
  1270
/* Messages */ // Madhu - support after libc team supported.
sl@0
  1271
sl@0
  1272
 
sl@0
  1273
sl@0
  1274
 int _Locale_catopen(L_messages_t* lmessage, const char* catalogName)
sl@0
  1275
 { 
sl@0
  1276
 	lmessage->domain = __getString((char*)catalogName);
sl@0
  1277
 	return 1;//catopen(catalogName,/*NL_CAT_LOCALE*/1); 
sl@0
  1278
 }
sl@0
  1279
 
sl@0
  1280
 void _Locale_catclose(L_messages_t* lmessage, int /*catalog_desc*/) 
sl@0
  1281
 {
sl@0
  1282
 	//setlocale(LC_MESSAGES, lmessage->name);
sl@0
  1283
 	delete(lmessage->domain);
sl@0
  1284
 	lmessage->domain = NULL;
sl@0
  1285
 	//catclose(catalog_desc);
sl@0
  1286
 
sl@0
  1287
 }
sl@0
  1288
 
sl@0
  1289
 const char* _Locale_catgets(L_messages_t* lmessage, int /*catalog_desc*/,
sl@0
  1290
                                       int /*set*/, int /*message*/,
sl@0
  1291
                                       const char *dfault)
sl@0
  1292
 { 
sl@0
  1293
 	char* locale = setlocale(LC_ALL, lmessage->name);
sl@0
  1294
#ifdef _MESSAGE_CATALOG_ 	
sl@0
  1295
 	textdomain(lmessage->domain);	
sl@0
  1296
	
sl@0
  1297
 	return gettext(dfault);
sl@0
  1298
#else
sl@0
  1299
	return NULL;
sl@0
  1300
#endif
sl@0
  1301
sl@0
  1302
 }
sl@0
  1303
sl@0
  1304
#ifdef __cplusplus    
sl@0
  1305
} /* extern C */
sl@0
  1306
_STLP_END_NAMESPACE
sl@0
  1307
#endif
sl@0
  1308
sl@0
  1309
#endif /* real locale */