2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
8 #include <libraries/locale.h>
9 #include <proto/locale.h> */
11 #define ADDS(st) tmp=strftime(s,maxsize-size,(st),timeptr);break;
13 #define ADDN(a,b) tmp=strfnumb(s,maxsize-size,(a),(b));break;
15 #define STOR(c) if(++size<=maxsize)*s++=(c);
19 (__localevec[LC_TIME-1]==NULL?strings[(a)-1]:GetLocaleStr(__localevec[LC_TIME-1],(a)))
21 #define STR(a) (strings[(a)-1])
24 /* extern struct Locale *__localevec[]; */
26 /* All calendar strings */
27 static const unsigned char *strings
[]=
30 "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday",
32 "Sun","Mon","Tue","Wed","Thu","Fri","Sat",
34 "January","February","March","April","May","June",
35 "July","August","September","October","November","December",
37 "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",
49 static size_t strfnumb(char *s
, size_t maxsize
, signed int places
, size_t value
)
55 size
= strfnumb(s
, maxsize
, places
- 1, value
/ 10);
59 size
= strfnumb(s
, maxsize
, places
+ 1, value
/ 10);
63 while ((places
++ < -1) && (++size
<= maxsize
))
69 if (++size
<= maxsize
) s
[size
- 1] = (value
% 10 + '0');
74 size_t strftime(char *s
, size_t maxsize
, const char *format
, const struct tm
*timeptr
)
78 if (format
== NULL
|| timeptr
== NULL
) return 0;
89 ADDS(STR(ABDAY_1
+timeptr
->tm_wday
+1));
92 ADDS(STR(ABMON_1
+timeptr
->tm_mon
+1));
96 ADDN(2,timeptr
->tm_mday
);
98 ADDN(-2,timeptr
->tm_mday
);
100 ADDN(3,timeptr
->tm_yday
+1);
102 ADDN(-2,timeptr
->tm_hour
);
104 ADDN(-2,timeptr
->tm_hour
%12+(timeptr
->tm_hour
%12==0)*12);
106 ADDN(2,timeptr
->tm_mon
+1);
108 ADDS(STR(AM_STR
+(timeptr
->tm_hour
>=12)));
112 ADDN(1,timeptr
->tm_wday
);
114 ADDS("%m/%d/%y %H:%M:%S");
116 ADDN(2,timeptr
->tm_year
%100);
118 ADDS(STR(DAY_1
+timeptr
->tm_wday
+1));
120 ADDS(STR(MON_1
+timeptr
->tm_mon
+1));
122 ADDS("%a %b %e %H:%M:%S %Y");
126 ADDN(2,timeptr
->tm_hour
);
128 ADDN(2,timeptr
->tm_hour
%12+(timeptr
->tm_hour
%12==0)*12);
130 ADDN(2,timeptr
->tm_min
);
134 ADDN(2,timeptr
->tm_sec
);
139 ADDN(2,(timeptr
->tm_yday
+7-timeptr
->tm_wday
)/7);
141 ADDN(2,(timeptr
->tm_yday
+7-(6+timeptr
->tm_wday
)%7)/7);
143 ADDN(4,timeptr
->tm_year
+1900);
175 if (maxsize
) /* Don't know if this is necessary, therefore it's here ;-) */
177 s
[maxsize
- 1] = '\0';