os/ossrv/genericopenlibs/cstdlib/LTIME/STRFTIME.C
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) 1997-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
* NAME:
sl@0
    16
* strftime - convert date and time to a string 
sl@0
    17
* SYNOPSIS:
sl@0
    18
* size_t strftime (char *array, size_t limitsize,const char*pattern,const struct tm *tme)
sl@0
    19
* Formats  Time into string for  the given tags[options] with a  limit of  Limitsize bytes.
sl@0
    20
* Options:
sl@0
    21
* %a - Abbreviated weekday name (eg:Mon)
sl@0
    22
* %A - Full weekday name (eg:Monday)
sl@0
    23
* %b - Abbreviated month name (eg:Jan)
sl@0
    24
* %B - full month name (eg:January)
sl@0
    25
* %c - preferred date and time representation (eg:Tue 06 12:34:45 2009)
sl@0
    26
* %C - century number (the year divided by 100 and truncated to an integer, range 00 to 99)
sl@0
    27
* %d - Day of the month as a decimal number (range 01 to 31)
sl@0
    28
* %D - Same as %m/%d/%y
sl@0
    29
* %e - Day of the month as a decimal number, a single digit is preceded by a space (range ' 1' to '31')
sl@0
    30
* %F- Equivalent to %Y-%m-%d 
sl@0
    31
* %g - Same As %G, but without the century.
sl@0
    32
* %G - The 4-digit year corresponding to the ISO week number (see %V). This has the same format and value as %Y, except that if the ISO week number belongs to the previous or next year, that year is used instead.
sl@0
    33
* %h - Same as %b
sl@0
    34
* %H - Hour as a decimal number using a 24-hour clock (range 00 to 23)
sl@0
    35
* %I - Hour as a decimal number using a 12-hour clock (range 01 to 12)
sl@0
    36
* %j - Day of the year as a decimal number (range 001 to 366)
sl@0
    37
* %m - Month as a decimal number (range 01 to 12)
sl@0
    38
* %M - Minute as a decimal number
sl@0
    39
* %n - Newline character
sl@0
    40
* %p - UPPER-CASE `AM' or `PM' according to the given time value
sl@0
    41
* %P - Lower-case `am' or `pm' according to the given time value
sl@0
    42
* %r - Time in a.m. and p.m. notation
sl@0
    43
* %R - Time in 24 hour notation
sl@0
    44
* %S - Second as a decimal number
sl@0
    45
* %t - Tab character
sl@0
    46
* %T - Current time, Equal to %H:%M:%S
sl@0
    47
* %u - Weekday as a decimal number [1,7], with 1 representing Monday
sl@0
    48
* %U - Week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week
sl@0
    49
* %V - The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week. (Use %G or %g for the year component that corresponds to the week number for the specified timestamp.)
sl@0
    50
* %W - Week number of the current year as a decimal number, starting with the first Monday as the first day of the first week
sl@0
    51
* %w - Day of the week as a decimal, Sunday being 0
sl@0
    52
* %x - Preferred date representation for the current locale without the time
sl@0
    53
* %X - Preferred time representation for the current locale without the date
sl@0
    54
* %y - Year as a decimal number without a century (range 00 to 99)
sl@0
    55
* %Y - Year as a decimal number including the century
sl@0
    56
* %Z or %z - Time zone offset or name or abbreviation (Operating System dependent)
sl@0
    57
* %% - percent sign
sl@0
    58
* Maximum length of this parameter is 1023 characters. 
sl@0
    59
* 
sl@0
    60
*
sl@0
    61
*/
sl@0
    62
sl@0
    63
sl@0
    64
sl@0
    65
#include <time.h>
sl@0
    66
#include <stdio.h>
sl@0
    67
#include <stddef.h>
sl@0
    68
#include <stdlib.h>  
sl@0
    69
#include <string.h>
sl@0
    70
sl@0
    71
static const int dayname_length[7] ={6, 6, 7, 9, 8, 6, 8};
sl@0
    72
static const char*const  adayname[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
sl@0
    73
sl@0
    74
static const char *const dayname[7] ={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
sl@0
    75
sl@0
    76
static const int monthname_length[12] ={7, 8, 5, 5, 3, 4, 4, 6, 9, 7, 8, 8};
sl@0
    77
sl@0
    78
static const char *const amonthname[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
sl@0
    79
sl@0
    80
static const char *const monthname[12] ={"January", "February", "March", "April","May", "June", "July", "August", "September", "October", "November","December"};
sl@0
    81
sl@0
    82
sl@0
    83
//  The Function Stores all characters  in Char * array,until it finds %.
sl@0
    84
int splitter(char *array,size_t limitsize,const char** format,size_t* counter)
sl@0
    85
{
sl@0
    86
	while(**format!='%' && **format)
sl@0
    87
	   {
sl@0
    88
		 if(*counter<limitsize-1 )
sl@0
    89
			{
sl@0
    90
				array[*counter]=**format;
sl@0
    91
				 (*counter)++;
sl@0
    92
				(*format)++;
sl@0
    93
			}
sl@0
    94
     
sl@0
    95
		 else
sl@0
    96
			{
sl@0
    97
				return  1;
sl@0
    98
			}		
sl@0
    99
	  }
sl@0
   100
	 array[*counter]='\0';
sl@0
   101
	 return 0;
sl@0
   102
}
sl@0
   103
// The Funtion is Used for Storing Abbreviated WeekDay Nname in Place of %a. (eg:Mon)
sl@0
   104
int funa(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   105
{
sl@0
   106
	 if(*counter<limitsize-1)
sl@0
   107
		{   
sl@0
   108
			strcat(array,adayname[tme->tm_wday]);
sl@0
   109
			*counter+=3;
sl@0
   110
		}
sl@0
   111
	else
sl@0
   112
		{
sl@0
   113
			return 1;
sl@0
   114
		}	
sl@0
   115
	return 0;
sl@0
   116
}
sl@0
   117
//The Function is Used for Stroring WeekDay Name in Place of %A. (eg:Monday)
sl@0
   118
int funA(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   119
{
sl@0
   120
	 if(*counter<limitsize-1)
sl@0
   121
		{
sl@0
   122
			strcat(array,dayname[tme->tm_wday]);
sl@0
   123
			*counter+=dayname_length[tme->tm_wday];                         
sl@0
   124
		}
sl@0
   125
	else
sl@0
   126
		{
sl@0
   127
			return 1;
sl@0
   128
		}
sl@0
   129
	return 0;
sl@0
   130
}  
sl@0
   131
// The  Function  is Used for Storing Abbreviated Month Name in Place of %b.(eg:Jan)
sl@0
   132
int funb(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   133
{
sl@0
   134
	if(*counter<limitsize-1)
sl@0
   135
		{
sl@0
   136
			strcat(array,amonthname[tme->tm_mon]);
sl@0
   137
			*counter+=3;                        
sl@0
   138
		}
sl@0
   139
	else
sl@0
   140
		{
sl@0
   141
			return  1;
sl@0
   142
		}	
sl@0
   143
	return 0;
sl@0
   144
}
sl@0
   145
// The  Function  is Used for Storing Month Name in Place of %B .(eg:January) 
sl@0
   146
int funB(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   147
{
sl@0
   148
	if(*counter<limitsize-1)
sl@0
   149
		{
sl@0
   150
			strcat(array,monthname[tme->tm_mon]);
sl@0
   151
			*counter+=monthname_length[tme->tm_mon];                         
sl@0
   152
		}
sl@0
   153
	else
sl@0
   154
		{
sl@0
   155
			return 1;
sl@0
   156
		}
sl@0
   157
	return 0;
sl@0
   158
}
sl@0
   159
// The Function is Used for Storing preferred date and time representation  in Place of %c.(eg:Tue 06 12:34:45 2009)
sl@0
   160
int func(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   161
{
sl@0
   162
	if(*counter<limitsize-24)
sl@0
   163
		{
sl@0
   164
			strcat(array,adayname[tme->tm_wday]);
sl@0
   165
			strcat(array," ");
sl@0
   166
			strcat(array,amonthname[tme->tm_mon]);
sl@0
   167
			*counter+=7;
sl@0
   168
			sprintf(&array[*counter]," %.2d %.2d %.2d %.2d %.4d",tme->tm_mday,tme->tm_hour,tme->tm_min,tme->tm_sec,1900+tme->tm_year);
sl@0
   169
			*counter+=17;
sl@0
   170
			array[*counter]='\0';
sl@0
   171
		}  	
sl@0
   172
	else
sl@0
   173
		{	
sl@0
   174
			return  1;
sl@0
   175
		}
sl@0
   176
	return 0; 
sl@0
   177
}
sl@0
   178
// The Function is Used for Storing  Century number in place of %C .(eg:he year divided by 100 and truncated to an integer, range 00 to 99)
sl@0
   179
int funC(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   180
{
sl@0
   181
	if(*counter<limitsize-1)
sl@0
   182
		{
sl@0
   183
			sprintf(&array[*counter],"%.2d",(1900+tme->tm_year)/100);
sl@0
   184
			*counter+=2;
sl@0
   185
			array[*counter]='\0';
sl@0
   186
		}
sl@0
   187
	else
sl@0
   188
		{
sl@0
   189
		return  1;
sl@0
   190
		}
sl@0
   191
	return 0;
sl@0
   192
}
sl@0
   193
// The Function is Used for Storing Day of the month as a decimal number in Place of %d.(eg:range 01 to 31)	
sl@0
   194
int fund(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   195
{
sl@0
   196
	if (*counter < limitsize - 2)
sl@0
   197
		{
sl@0
   198
		sprintf (&array[*counter], "%.2d", tme->tm_mday);
sl@0
   199
		*counter += 2;
sl@0
   200
		array[*counter]='\0';
sl@0
   201
		}
sl@0
   202
	else
sl@0
   203
		{
sl@0
   204
		return  1;
sl@0
   205
		}
sl@0
   206
	return 0;    	
sl@0
   207
}
sl@0
   208
// The Function is Used for Storing  Date in form of %m/%d/%y in Place of %D.
sl@0
   209
int funD(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   210
{
sl@0
   211
	if(*counter<limitsize-8)
sl@0
   212
		{
sl@0
   213
			sprintf(&array[*counter],"%.2d/%.2d/%.2d",tme->tm_mon,tme->tm_mday,(1900+tme->tm_year)%100);  
sl@0
   214
			*counter+=8;
sl@0
   215
			array[*counter]='\0';        
sl@0
   216
		}
sl@0
   217
	else
sl@0
   218
		{
sl@0
   219
			return  1;
sl@0
   220
		}	
sl@0
   221
	return 0;
sl@0
   222
}
sl@0
   223
// The Function is Used for Storing Day of the month as a Decimal number, a single digit is preceded by a space in Place of %e. (eg:range ' 1' to '31')
sl@0
   224
int fune(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   225
{
sl@0
   226
	if(*counter<limitsize-2)
sl@0
   227
		{
sl@0
   228
			if(tme->tm_mday<10)
sl@0
   229
				sprintf(&array[*counter]," %d",tme->tm_mday);
sl@0
   230
			else
sl@0
   231
				sprintf(&array[*counter],"%2d",tme->tm_mday);  
sl@0
   232
			*counter+=2; 
sl@0
   233
			array[*counter]='\0';                      
sl@0
   234
		}
sl@0
   235
	else
sl@0
   236
		{
sl@0
   237
			return  1;
sl@0
   238
		}
sl@0
   239
	return 0; 
sl@0
   240
                            
sl@0
   241
}
sl@0
   242
// The Function is Used for Storing date in form of  %Y-%m-%d 
sl@0
   243
int funF(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   244
{
sl@0
   245
	if(*counter<limitsize-10)
sl@0
   246
		{
sl@0
   247
			sprintf(&array[*counter],"%4d/%.2d/%.2d",1900+tme->tm_year,tme->tm_mon,tme->tm_mday);
sl@0
   248
			*counter+=10;
sl@0
   249
			array[*counter]='\0';
sl@0
   250
		}   
sl@0
   251
	else
sl@0
   252
		{
sl@0
   253
		return  1;
sl@0
   254
		}
sl@0
   255
	return 0;
sl@0
   256
}
sl@0
   257
// The Function is  same as that of funG but without Century
sl@0
   258
int fung(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   259
{
sl@0
   260
	if(*counter<limitsize-2)
sl@0
   261
		{
sl@0
   262
			sprintf(&array[*counter],"%.2d",(1900+tme->tm_year)%100);
sl@0
   263
			*counter+=2;
sl@0
   264
			array[*counter]='\0';
sl@0
   265
		}
sl@0
   266
	else
sl@0
   267
		{
sl@0
   268
			return  1;
sl@0
   269
		}	
sl@0
   270
	return 0;
sl@0
   271
}
sl@0
   272
// The Function is Used For Storing  4-digit year corresponding to the ISO week number  in place of %G
sl@0
   273
int funG(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   274
{
sl@0
   275
	if(*counter<limitsize-4)
sl@0
   276
		{
sl@0
   277
			sprintf(&array[*counter],"%4d",1900+tme->tm_year);
sl@0
   278
			*counter+=4;
sl@0
   279
			array[*counter]='\0';
sl@0
   280
		}
sl@0
   281
	else
sl@0
   282
		{	
sl@0
   283
			return  1;
sl@0
   284
		}	
sl@0
   285
	return 0;
sl@0
   286
}
sl@0
   287
// The Function is same as funb
sl@0
   288
int funh(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   289
{
sl@0
   290
	if(*counter<limitsize-1)
sl@0
   291
		{
sl@0
   292
		strcat(array,amonthname[tme->tm_mon]);
sl@0
   293
		*counter+=3;
sl@0
   294
		array[*counter]='\0';
sl@0
   295
		}
sl@0
   296
	else
sl@0
   297
		{
sl@0
   298
			return  1;
sl@0
   299
		}	
sl@0
   300
	return 0;   
sl@0
   301
}
sl@0
   302
// The Function is Used for Storing Hour as a decimal number using a 24-hour clock in Place of %H (eg:range 00 to 23)	
sl@0
   303
int funH(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   304
{	
sl@0
   305
	if (*counter < limitsize - 2)
sl@0
   306
		{
sl@0
   307
			sprintf (&array[*counter], "%.2d",
sl@0
   308
			tme->tm_hour);
sl@0
   309
			*counter += 2;
sl@0
   310
			array[*counter]='\0';
sl@0
   311
		}
sl@0
   312
	else
sl@0
   313
		{
sl@0
   314
			return  1;
sl@0
   315
		}
sl@0
   316
	return 0;  	
sl@0
   317
}
sl@0
   318
// The Function is Used for Storing Hour as a decimal number using a 12-hour clock in Place of %I(eg:range 01 to 12)
sl@0
   319
int funI(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   320
{
sl@0
   321
	if (*counter < limitsize - 2)
sl@0
   322
		{
sl@0
   323
			if(tme->tm_hour%12)
sl@0
   324
				sprintf(&array[*counter],"%.2d",tme->tm_hour%12);
sl@0
   325
			else
sl@0
   326
				strcat(array,"12");
sl@0
   327
			*counter+=2;
sl@0
   328
			array[*counter]='\0';
sl@0
   329
		}
sl@0
   330
	else
sl@0
   331
		{
sl@0
   332
			return  1;
sl@0
   333
		}
sl@0
   334
	return 0;   
sl@0
   335
}
sl@0
   336
// The Function is Used for Storing Day of the year as a decimal number in Place of %j (eg:range 001 to 366)
sl@0
   337
int funj(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   338
{
sl@0
   339
	if (*counter < limitsize - 3)
sl@0
   340
		{
sl@0
   341
			sprintf (&array[*counter], "%.3d", tme->tm_yday + 1);
sl@0
   342
			*counter += 3;
sl@0
   343
			array[*counter]='\0';
sl@0
   344
		}
sl@0
   345
	else
sl@0
   346
		{
sl@0
   347
			return  1;
sl@0
   348
		}
sl@0
   349
	return 0;  	
sl@0
   350
}
sl@0
   351
// The Function is Used for StoringThe hour (24-hour clock) as a decimal number (range  0  to  23);single digits are preceded by a blankin Place of %k
sl@0
   352
int funk(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   353
{
sl@0
   354
	if(*counter<limitsize-2)
sl@0
   355
		{
sl@0
   356
			if(tme->tm_hour<10)
sl@0
   357
				sprintf(&array[*counter]," %d",tme->tm_hour);
sl@0
   358
			else
sl@0
   359
				sprintf(&array[*counter],"%2d",tme->tm_hour);
sl@0
   360
			*counter+=2; 
sl@0
   361
			array[*counter]='\0';
sl@0
   362
		}
sl@0
   363
	else
sl@0
   364
		{
sl@0
   365
			return  1;
sl@0
   366
		}	
sl@0
   367
	return 0;    
sl@0
   368
}
sl@0
   369
// The Function is Used for Storing The  hour  (12-hour  clock) as a decimal number (range 1 to 12);single digits are preceded by a blank in Place of %l
sl@0
   370
int funl(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   371
{
sl@0
   372
	if (*counter < limitsize - 2)
sl@0
   373
		{
sl@0
   374
			if(tme->tm_hour%12)
sl@0
   375
				{
sl@0
   376
					if(tme->tm_hour%12<10)
sl@0
   377
						sprintf(&array[*counter],"% d",tme->tm_hour%12);
sl@0
   378
					else
sl@0
   379
						sprintf(&array[*counter],"%d",tme->tm_hour%12);
sl@0
   380
				}
sl@0
   381
			else
sl@0
   382
				strcat(array,"12");
sl@0
   383
			*counter+=2;
sl@0
   384
			array[*counter]='\0';
sl@0
   385
		}
sl@0
   386
	else
sl@0
   387
		{
sl@0
   388
			return  1;
sl@0
   389
		}
sl@0
   390
	return 0;       
sl@0
   391
}
sl@0
   392
// The Function is Used for Storing Month as a decimal number in Place of %m (eg:range 01 to 12)
sl@0
   393
int funm(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   394
{
sl@0
   395
	if (*counter < limitsize - 2)
sl@0
   396
		{
sl@0
   397
			sprintf (&array[*counter], "%.2d", tme->tm_mon + 1);
sl@0
   398
			*counter += 2;
sl@0
   399
			array[*counter]='\0';
sl@0
   400
		}
sl@0
   401
	else
sl@0
   402
		{
sl@0
   403
		return  1;
sl@0
   404
		}
sl@0
   405
	return 0;   	
sl@0
   406
}
sl@0
   407
// The Function is Used for Storing Minute as a decimal number in Place of %M
sl@0
   408
int funM(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   409
{
sl@0
   410
	if (*counter < limitsize - 2)
sl@0
   411
		{
sl@0
   412
			sprintf (&array[*counter], "%.2d", tme->tm_min);
sl@0
   413
			*counter += 2;
sl@0
   414
			array[*counter]='\0';
sl@0
   415
		}
sl@0
   416
	else
sl@0
   417
		{
sl@0
   418
			return  1;
sl@0
   419
		}
sl@0
   420
	return 0;  	
sl@0
   421
}
sl@0
   422
// The Function is Used for Storing `AM' or `PM' according to the given time  value,  or  the corresponding  strings  for the current locale.  Noon is treated as `pm' and midnight as `am'.
sl@0
   423
int funp(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   424
{
sl@0
   425
	if (*counter< limitsize - 2)
sl@0
   426
		{
sl@0
   427
			if (tme->tm_hour < 12)
sl@0
   428
				strcat(array,"A");
sl@0
   429
			else
sl@0
   430
				strcat(array,"P");
sl@0
   431
			strcat(array,"M");
sl@0
   432
			*counter+=2;
sl@0
   433
		}
sl@0
   434
	else
sl@0
   435
		{
sl@0
   436
			return  1;
sl@0
   437
		}
sl@0
   438
	return 0;   	
sl@0
   439
}
sl@0
   440
// The Function is Used for Storing `am' or `pm' according to the given time  value,  or  the corresponding  strings  for the current locale.  Noon is treated as `pm' and midnight as `am'.
sl@0
   441
int funP(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   442
{	
sl@0
   443
	if (*counter< limitsize - 2)
sl@0
   444
		{
sl@0
   445
			if (tme->tm_hour < 12)
sl@0
   446
				strcat(array,"a");
sl@0
   447
			else
sl@0
   448
				strcat(array,"p");
sl@0
   449
			strcat(array,"m");
sl@0
   450
			*counter+=2;
sl@0
   451
		}
sl@0
   452
	else
sl@0
   453
		{
sl@0
   454
			return  1;
sl@0
   455
		}
sl@0
   456
	return 0;
sl@0
   457
}
sl@0
   458
//The Function is Used for Storing  Hour,minute,second,time value in place of %r,same as %I:%M:%S %p'
sl@0
   459
int funr(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   460
{
sl@0
   461
	if (*counter< limitsize - 11)
sl@0
   462
		{
sl@0
   463
			if(tme->tm_hour%12)
sl@0
   464
				{
sl@0
   465
					if(tme->tm_hour%12<10)
sl@0
   466
						sprintf(&array[*counter],"% d",tme->tm_hour);
sl@0
   467
					else
sl@0
   468
						sprintf(&array[*counter],"%d",tme->tm_hour);
sl@0
   469
				}
sl@0
   470
			else
sl@0
   471
				strcat(array,"12");  
sl@0
   472
			*counter+=2;
sl@0
   473
			array[*counter]='\0';
sl@0
   474
			strcat(array,":");
sl@0
   475
			*counter+=1;
sl@0
   476
			sprintf (&array[*counter], "%.2d", tme->tm_min);
sl@0
   477
			*counter += 2;
sl@0
   478
			array[*counter]='\0';
sl@0
   479
			strcat(array,":");
sl@0
   480
			*counter+=1;
sl@0
   481
			sprintf (&array[*counter], "%2.2d",tme->tm_sec);
sl@0
   482
			*counter += 2;
sl@0
   483
			array[*counter]='\0';
sl@0
   484
			strcat(array," ");
sl@0
   485
			*counter+=1;
sl@0
   486
			if (tme->tm_hour < 12)
sl@0
   487
				strcat(array,"A");
sl@0
   488
			else
sl@0
   489
				strcat(array,"P");
sl@0
   490
			strcat(array,"M");
sl@0
   491
			*counter+=2;
sl@0
   492
		}
sl@0
   493
	else
sl@0
   494
		{
sl@0
   495
			return  1;
sl@0
   496
		}
sl@0
   497
	return 0; 
sl@0
   498
     
sl@0
   499
}
sl@0
   500
//   The Function is Used for Storing  The time in 24-hour notation in Place of %R .Same as (%H:%M)..
sl@0
   501
int funR(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   502
{
sl@0
   503
    if (*counter< limitsize - 5)
sl@0
   504
    {
sl@0
   505
     sprintf (&array[*counter], "%.2d",
sl@0
   506
		       tme->tm_hour);
sl@0
   507
     strcat(array,":");
sl@0
   508
     *counter+=3;
sl@0
   509
      sprintf (&array[*counter], "%.2d", tme->tm_min);
sl@0
   510
	      *counter += 2;
sl@0
   511
	      array[*counter]='\0';
sl@0
   512
       }
sl@0
   513
       else
sl@0
   514
	       {
sl@0
   515
		   return  1;
sl@0
   516
		}	   
sl@0
   517
    return 0;
sl@0
   518
    
sl@0
   519
}
sl@0
   520
//   The Function is Used for Storing The  number  of  seconds since the Epoch, i.e., since 1970-01-0  0:00:00 UTC.in place of %s
sl@0
   521
int funs(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   522
{
sl@0
   523
	size_t count=0;
sl@0
   524
	size_t temptime;
sl@0
   525
	time_t timeinseconds;
sl@0
   526
	timeinseconds = time (NULL);
sl@0
   527
	temptime=timeinseconds;
sl@0
   528
	while(temptime>0)
sl@0
   529
		{
sl@0
   530
			count++;
sl@0
   531
			temptime/=10;
sl@0
   532
		}
sl@0
   533
	if(*counter<limitsize-count)
sl@0
   534
		{
sl@0
   535
			sprintf(&array[*counter],"%ld",timeinseconds);
sl@0
   536
			*counter+=count;
sl@0
   537
			array[*counter]='\0';
sl@0
   538
		}
sl@0
   539
	else
sl@0
   540
		{
sl@0
   541
		return  1;
sl@0
   542
		}
sl@0
   543
	return 0;
sl@0
   544
    
sl@0
   545
}
sl@0
   546
//   The Function is Used for Storing   The second as a decimal number (eg:range 00 to 60)
sl@0
   547
int funS(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   548
{
sl@0
   549
	if (*counter < limitsize - 2)
sl@0
   550
		{
sl@0
   551
			sprintf (&array[*counter], "%.2d", tme->tm_sec);
sl@0
   552
			*counter += 2;
sl@0
   553
			array[*counter]='\0';
sl@0
   554
		}
sl@0
   555
	else
sl@0
   556
		{
sl@0
   557
			return  1;
sl@0
   558
		}
sl@0
   559
	return 0;     	
sl@0
   560
}
sl@0
   561
//   The Function is Used for Storing  The time in 24-hour notation (%H:%M:%S) in place of %T
sl@0
   562
int funT(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   563
{
sl@0
   564
	 if (*counter < limitsize - 2)
sl@0
   565
		 {
sl@0
   566
			 sprintf (&array[*counter], "%.2d",tme->tm_hour);
sl@0
   567
			 *counter+=2;
sl@0
   568
			 array[*counter]='\0';
sl@0
   569
			 strcat(array,":");
sl@0
   570
			 *counter += 1; 
sl@0
   571
			 sprintf (&array[*counter], "%.2d", tme->tm_min);
sl@0
   572
			 *counter+=2;
sl@0
   573
			 array[*counter]='\0';
sl@0
   574
			 strcat(array,":");
sl@0
   575
			 *counter += 1;
sl@0
   576
			 sprintf (&array[*counter], "%.2d", tme->tm_sec);
sl@0
   577
			 *counter += 2;
sl@0
   578
			 array[*counter]='\0';
sl@0
   579
		} 
sl@0
   580
	else
sl@0
   581
		{
sl@0
   582
			return  1;
sl@0
   583
		}
sl@0
   584
	return 0;
sl@0
   585
}
sl@0
   586
//   The Function is Used for Storing The  day of the week as a decimal, range 1 to 7, Monday being 1 in Place of %U.
sl@0
   587
	
sl@0
   588
int funu(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   589
{
sl@0
   590
	if (*counter < limitsize - 1)
sl@0
   591
		{
sl@0
   592
			sprintf (&array[*counter], "%.1d",tme->tm_wday);
sl@0
   593
			*counter+=1;
sl@0
   594
			array[*counter]='\0';
sl@0
   595
		}
sl@0
   596
	else
sl@0
   597
		{
sl@0
   598
			return  1;
sl@0
   599
		}
sl@0
   600
	return 0;    
sl@0
   601
}
sl@0
   602
//   The Function is Used for Storing The week number of the current year as a decimal  number,  range  00  to  53,  starting  with the first Sunday as the first day of week 01 in Place of %U
sl@0
   603
int funU(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   604
{
sl@0
   605
	if (*counter < limitsize - 2) 
sl@0
   606
		{
sl@0
   607
			int  temp= tme->tm_yday/7;
sl@0
   608
			if (tme->tm_yday%7 >tme->tm_wday)
sl@0
   609
				temp++;
sl@0
   610
			sprintf(&array[*counter],"%.2d",temp);
sl@0
   611
			*counter+=2;
sl@0
   612
			array[*counter]='\0';
sl@0
   613
		}
sl@0
   614
	else
sl@0
   615
		{
sl@0
   616
			return   1;
sl@0
   617
		}
sl@0
   618
	return 0;      	
sl@0
   619
}
sl@0
   620
//   The Function is Used for Storing The  day of the week as a decimal, range 0 to 6, Sunday being 0 in Place of %w
sl@0
   621
int funw(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   622
{
sl@0
   623
	if (*counter < limitsize - 1)
sl@0
   624
		{
sl@0
   625
			sprintf (&array[*counter], "%.1d",tme->tm_wday);
sl@0
   626
			*counter+=1;
sl@0
   627
			array[*counter]='\0';
sl@0
   628
		}
sl@0
   629
	else
sl@0
   630
		{
sl@0
   631
			return  1;
sl@0
   632
		}
sl@0
   633
	return 0;    	
sl@0
   634
}
sl@0
   635
//   The Function is Used for Storing The week number of the current year as a decimal  number,  range 00  to  53,  starting  with the first Monday as the first day of week 01 in Place of %W
sl@0
   636
sl@0
   637
int funW(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   638
{
sl@0
   639
	if (*counter < limitsize - 2) 
sl@0
   640
		{
sl@0
   641
			int temp= tme->tm_yday/7;
sl@0
   642
			if (tme->tm_yday%7 > (tme->tm_wday+6)%7)
sl@0
   643
				temp++;
sl@0
   644
			sprintf(&array[*counter],"%.2d",temp);
sl@0
   645
			*counter+=2;
sl@0
   646
			array[*counter]='\0';
sl@0
   647
		}
sl@0
   648
	else
sl@0
   649
		{
sl@0
   650
			return  1;
sl@0
   651
		}
sl@0
   652
	return 0;
sl@0
   653
}
sl@0
   654
// The Function is Used for Storing preferred date representation for the current locale without   the time in Place of %x
sl@0
   655
int funx(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   656
{
sl@0
   657
	if (*counter < limitsize - 15)
sl@0
   658
		{
sl@0
   659
			strcat(array,adayname[tme->tm_wday]);
sl@0
   660
			*counter+=3;
sl@0
   661
			array[*counter]='\0';
sl@0
   662
			strcat(array," ");
sl@0
   663
			*counter+=1;
sl@0
   664
			strcat(array,amonthname[tme->tm_mon]);
sl@0
   665
			strcat(array," ");
sl@0
   666
			*counter+=4;
sl@0
   667
			sprintf (&array[*counter]," %.2d %.4d", tme->tm_mday,1900 + tme->tm_year);
sl@0
   668
			*counter += 8;
sl@0
   669
			array[*counter]='\0';
sl@0
   670
		}
sl@0
   671
	else
sl@0
   672
		{	
sl@0
   673
			return  1;
sl@0
   674
		}
sl@0
   675
	return 0;    	
sl@0
   676
}
sl@0
   677
// The Function is Used for Storing  preferred time representation for the current locale without the date in Place of %X
sl@0
   678
int funX(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   679
{
sl@0
   680
	if (*counter < limitsize - 8)
sl@0
   681
		{
sl@0
   682
			sprintf (&array[*counter],"%2.2d:%2.2d:%2.2d",tme->tm_hour, tme->tm_min,tme->tm_sec);
sl@0
   683
			*counter += 8;
sl@0
   684
			array[*counter]='\0';
sl@0
   685
		}
sl@0
   686
	else
sl@0
   687
		{
sl@0
   688
			return  1;
sl@0
   689
		}
sl@0
   690
	return 0;     	
sl@0
   691
}
sl@0
   692
// The Function is Used for Storing  year as a decimal number without a century (range 00 to 99). in Place of %y
sl@0
   693
int funy(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   694
{
sl@0
   695
	if (*counter < limitsize - 2)
sl@0
   696
		{
sl@0
   697
			sprintf (&array[*counter], "%.2d",tme->tm_year);
sl@0
   698
			*counter += 2;
sl@0
   699
			array[*counter]='\0';
sl@0
   700
		}
sl@0
   701
	else
sl@0
   702
		{
sl@0
   703
			return  1;
sl@0
   704
		}
sl@0
   705
	return 0;   	
sl@0
   706
}
sl@0
   707
// The Function is Used for Storing  The year as a decimal number including the century in Place of %Y
sl@0
   708
int funY(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0
   709
{
sl@0
   710
	if (*counter < limitsize - 4)
sl@0
   711
		{
sl@0
   712
			sprintf (&array[*counter], "%.4d",1900 + tme->tm_year);
sl@0
   713
			*counter += 4;
sl@0
   714
			array[*counter]='\0';
sl@0
   715
		}
sl@0
   716
	else
sl@0
   717
		{
sl@0
   718
			return  1;
sl@0
   719
		}
sl@0
   720
	return 0;   	
sl@0
   721
}
sl@0
   722
sl@0
   723
//- convert/Formats date and time to a string for  the given tags[options] with a  limit of  Limitsize bytes
sl@0
   724
// It formats the broken-down time  according to the format specification format and places the result in the  character  array of  Limitsize .The Function returns the number of characters written in the array,
sl@0
   725
// if successful and 0 if  the size exceeeds the limit .
sl@0
   726
sl@0
   727
EXPORT_C size_t strftime (char *array, size_t limitsize,const char*pattern,const struct tm *tme)
sl@0
   728
{          
sl@0
   729
	size_t* counter=(size_t* )malloc(sizeof(size_t));
sl@0
   730
	size_t error=0,funerror=0;
sl@0
   731
	*counter=0;
sl@0
   732
	array[*counter]='\0';
sl@0
   733
	while(1)
sl@0
   734
		{
sl@0
   735
			error=splitter(array,limitsize,&pattern,counter);
sl@0
   736
			if(!error)
sl@0
   737
				{
sl@0
   738
					if(*pattern=='\0')
sl@0
   739
						break;
sl@0
   740
					else
sl@0
   741
						{
sl@0
   742
							pattern++;
sl@0
   743
							switch(*pattern)
sl@0
   744
								{
sl@0
   745
									case '%':
sl@0
   746
										if(*counter<limitsize-1)
sl@0
   747
											array[(*counter)++]='%';
sl@0
   748
										else
sl@0
   749
											return  0;
sl@0
   750
										break;
sl@0
   751
									case 'a':
sl@0
   752
										funerror= funa(array,limitsize,counter,tme);
sl@0
   753
										if(funerror)
sl@0
   754
											return  0;
sl@0
   755
										break;
sl@0
   756
									case 'A':
sl@0
   757
										funerror=funA(array,limitsize,counter,tme);
sl@0
   758
										if(funerror)
sl@0
   759
											return 0;
sl@0
   760
										break;
sl@0
   761
									case 'b':
sl@0
   762
										funerror=funb(array,limitsize,counter,tme);
sl@0
   763
										if(funerror)
sl@0
   764
											return  0;
sl@0
   765
										break;
sl@0
   766
									case 'B':
sl@0
   767
										funerror=funB(array,limitsize,counter,tme);
sl@0
   768
										if(funerror)
sl@0
   769
											return  0;
sl@0
   770
										break;
sl@0
   771
									case 'c':
sl@0
   772
										funerror=func(array,limitsize,counter,tme);
sl@0
   773
										if(funerror)
sl@0
   774
											return  0;
sl@0
   775
										break;
sl@0
   776
									case 'C':
sl@0
   777
										funerror=funC(array,limitsize,counter,tme);
sl@0
   778
										if(funerror)
sl@0
   779
											return  0;
sl@0
   780
										break;
sl@0
   781
									case 'd':
sl@0
   782
										funerror=fund(array,limitsize,counter,tme);
sl@0
   783
										if(funerror)
sl@0
   784
											return  0;
sl@0
   785
										break;
sl@0
   786
									case 'D':
sl@0
   787
										funerror=funD(array,limitsize,counter,tme);
sl@0
   788
										if(funerror)
sl@0
   789
											return  0;
sl@0
   790
										break; 
sl@0
   791
									case 'e':
sl@0
   792
										funerror=fune(array,limitsize,counter,tme);
sl@0
   793
										if(funerror)
sl@0
   794
											return  0;
sl@0
   795
										break;
sl@0
   796
									case 'F':
sl@0
   797
										funerror=funF(array,limitsize,counter,tme);
sl@0
   798
										if(funerror)
sl@0
   799
											return  0;
sl@0
   800
										break;         
sl@0
   801
									case 'g':
sl@0
   802
										funerror=fung(array,limitsize,counter,tme);
sl@0
   803
										if(funerror)
sl@0
   804
											return  0;
sl@0
   805
										break;  
sl@0
   806
									case 'G':
sl@0
   807
										funerror=funG(array,limitsize,counter,tme);
sl@0
   808
										if(funerror)
sl@0
   809
											return  0;
sl@0
   810
										break;
sl@0
   811
									case 'H':
sl@0
   812
										funerror=funH(array,limitsize,counter,tme);
sl@0
   813
										if(funerror)
sl@0
   814
											return  0;
sl@0
   815
										break;
sl@0
   816
									case 'I':
sl@0
   817
										funerror=funI(array,limitsize,counter,tme);
sl@0
   818
										if(funerror)
sl@0
   819
											return  0;
sl@0
   820
										break;
sl@0
   821
									case 'j':
sl@0
   822
										funerror=funj(array,limitsize,counter,tme);
sl@0
   823
										if(funerror)
sl@0
   824
											return  0;
sl@0
   825
										break;
sl@0
   826
									case 'k':
sl@0
   827
										funerror=funk(array,limitsize,counter,tme);
sl@0
   828
										if(funerror)
sl@0
   829
											return  0;
sl@0
   830
										break;
sl@0
   831
									case 'l':
sl@0
   832
										funerror=funl(array,limitsize,counter,tme);
sl@0
   833
										if(funerror)
sl@0
   834
											return  0;
sl@0
   835
										break;
sl@0
   836
									case 'm':
sl@0
   837
										funerror=funm(array,limitsize,counter,tme);
sl@0
   838
										if(funerror)
sl@0
   839
											return  0;
sl@0
   840
										break;
sl@0
   841
									case 'M':
sl@0
   842
										funerror=funM(array,limitsize,counter,tme);
sl@0
   843
										if(funerror)
sl@0
   844
											return  0;
sl@0
   845
										break;
sl@0
   846
									case 'p':
sl@0
   847
										funerror=funp(array,limitsize,counter,tme);
sl@0
   848
										if(funerror)
sl@0
   849
											return  0;
sl@0
   850
										break;
sl@0
   851
									case 'P':
sl@0
   852
										funerror=funP(array,limitsize,counter,tme);
sl@0
   853
										if(funerror)
sl@0
   854
											return  0;
sl@0
   855
										break;
sl@0
   856
									case 'r':
sl@0
   857
										funerror=funr(array,limitsize,counter,tme);
sl@0
   858
										if(funerror)
sl@0
   859
											return  0;
sl@0
   860
										break;
sl@0
   861
									case 'R':
sl@0
   862
										funerror=funR(array,limitsize,counter,tme);
sl@0
   863
										if(funerror)
sl@0
   864
											return  0;
sl@0
   865
										break; 
sl@0
   866
									case 's':
sl@0
   867
										funerror=funs(array,limitsize,counter,tme);
sl@0
   868
										if(funerror)
sl@0
   869
											return  0;
sl@0
   870
										break;
sl@0
   871
									case 'S':
sl@0
   872
										funerror=funS(array,limitsize,counter,tme);
sl@0
   873
										if(funerror)
sl@0
   874
											return  0;
sl@0
   875
										break;
sl@0
   876
									case 'T':
sl@0
   877
										funerror=funT(array,limitsize,counter,tme);
sl@0
   878
										if(funerror)
sl@0
   879
											return  0;
sl@0
   880
										break;
sl@0
   881
									case 'u':
sl@0
   882
										funerror=funu(array,limitsize,counter,tme);
sl@0
   883
										if(funerror)
sl@0
   884
											return  0;
sl@0
   885
										break;
sl@0
   886
									case 'U':
sl@0
   887
										funerror=funU(array,limitsize,counter,tme);
sl@0
   888
										if(funerror)
sl@0
   889
											return  0;
sl@0
   890
										break;
sl@0
   891
									case 'w':
sl@0
   892
										funerror=funw(array,limitsize,counter,tme);
sl@0
   893
										if(funerror)
sl@0
   894
											return  0;
sl@0
   895
										break;
sl@0
   896
									case 'W':
sl@0
   897
										funerror=funW(array,limitsize,counter,tme);
sl@0
   898
										if(funerror)
sl@0
   899
											return  0;
sl@0
   900
										break;
sl@0
   901
									case 'x':
sl@0
   902
										funerror=funx(array,limitsize,counter,tme);
sl@0
   903
										if(funerror)
sl@0
   904
											return  0;
sl@0
   905
										break;
sl@0
   906
									case 'X':
sl@0
   907
										funerror=funX(array,limitsize,counter,tme);
sl@0
   908
										if(funerror)
sl@0
   909
											return  0;
sl@0
   910
										break;
sl@0
   911
									case'y':
sl@0
   912
										funerror=funy(array,limitsize,counter,tme);
sl@0
   913
										if(funerror)
sl@0
   914
											return  0;
sl@0
   915
										break;
sl@0
   916
									case 'Y':
sl@0
   917
										funerror=funY(array,limitsize,counter,tme);
sl@0
   918
										if(funerror)
sl@0
   919
											return  0;
sl@0
   920
										break;
sl@0
   921
									case 'Z':
sl@0
   922
										break;
sl@0
   923
								}		
sl@0
   924
						}
sl@0
   925
				}		
sl@0
   926
			else
sl@0
   927
				{
sl@0
   928
					return  0;
sl@0
   929
				}
sl@0
   930
			if (*pattern)
sl@0
   931
				pattern++;
sl@0
   932
			else
sl@0
   933
				break;
sl@0
   934
		}
sl@0
   935
	array[*counter]='\0';
sl@0
   936
	error=*counter;
sl@0
   937
	free (counter);
sl@0
   938
	counter=NULL;
sl@0
   939
	return error;
sl@0
   940
}