Mercurial > hg > xemacs-beta
comparison src/strftime.c @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | de805c49cfc1 |
children |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
92 | 92 |
93 #ifndef STDC_HEADERS | 93 #ifndef STDC_HEADERS |
94 time_t mktime (); | 94 time_t mktime (); |
95 #endif | 95 #endif |
96 | 96 |
97 #if defined(WIN32_NATIVE) || defined(CYGWIN) | 97 #if defined(WINDOWSNT) || defined(__CYGWIN32__) |
98 #include <time.h> | 98 #include <time.h> |
99 #else | 99 #else |
100 #if defined(HAVE_TZNAME) | 100 #if defined(HAVE_TZNAME) |
101 extern char *tzname[2]; | 101 extern char *tzname[2]; |
102 #endif | 102 #endif |
103 #endif /* WIN32_NATIVE */ | 103 #endif /* WINDOWSNT */ |
104 | 104 |
105 #ifdef emacs | 105 #ifdef emacs |
106 #define strftime emacs_strftime | 106 #define strftime emacs_strftime |
107 #endif | 107 #endif |
108 | 108 |
110 enum padding | 110 enum padding |
111 { | 111 { |
112 none, blank, zero | 112 none, blank, zero |
113 }; | 113 }; |
114 | 114 |
115 static char const* const days[] = | 115 static char CONST* CONST days[] = |
116 { | 116 { |
117 "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" | 117 "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" |
118 }; | 118 }; |
119 | 119 |
120 static char const * const months[] = | 120 static char CONST * CONST months[] = |
121 { | 121 { |
122 "January", "February", "March", "April", "May", "June", | 122 "January", "February", "March", "April", "May", "June", |
123 "July", "August", "September", "October", "November", "December" | 123 "July", "August", "September", "October", "November", "December" |
124 }; | 124 }; |
125 | 125 |
172 } | 172 } |
173 | 173 |
174 /* Like strncpy except return the number of characters copied. */ | 174 /* Like strncpy except return the number of characters copied. */ |
175 | 175 |
176 static int | 176 static int |
177 add_str (char *to, const char *from, int max) | 177 add_str (char *to, CONST char *from, int max) |
178 { | 178 { |
179 int i; | 179 int i; |
180 | 180 |
181 for (i = 0; from[i] && i <= max; ++i) | 181 for (i = 0; from[i] && i <= max; ++i) |
182 to[i] = from[i]; | 182 to[i] = from[i]; |
201 | 201 |
202 /* Return the week in the year of the time in TM, with the weeks | 202 /* Return the week in the year of the time in TM, with the weeks |
203 starting on Sundays. */ | 203 starting on Sundays. */ |
204 | 204 |
205 static int | 205 static int |
206 sun_week (const struct tm *tm) | 206 sun_week (CONST struct tm *tm) |
207 { | 207 { |
208 int dl; | 208 int dl; |
209 | 209 |
210 /* Set `dl' to the day in the year of the last day of the week previous | 210 /* Set `dl' to the day in the year of the last day of the week previous |
211 to the one containing the day specified in TM. If the day specified | 211 to the one containing the day specified in TM. If the day specified |
218 | 218 |
219 /* Return the week in the year of the time in TM, with the weeks | 219 /* Return the week in the year of the time in TM, with the weeks |
220 starting on Mondays. */ | 220 starting on Mondays. */ |
221 | 221 |
222 static int | 222 static int |
223 mon_week (const struct tm *tm) | 223 mon_week (CONST struct tm *tm) |
224 { | 224 { |
225 int dl, wday; | 225 int dl, wday; |
226 | 226 |
227 if (tm->tm_wday == 0) | 227 if (tm->tm_wday == 0) |
228 wday = 6; | 228 wday = 6; |
231 dl = tm->tm_yday - wday; | 231 dl = tm->tm_yday - wday; |
232 return dl <= 0 ? 0 : dl / 7 + (dl % 7 != 0); | 232 return dl <= 0 ? 0 : dl / 7 + (dl % 7 != 0); |
233 } | 233 } |
234 | 234 |
235 #if !defined(HAVE_TM_ZONE) && !defined(HAVE_TZNAME) | 235 #if !defined(HAVE_TM_ZONE) && !defined(HAVE_TZNAME) |
236 char *zone_name (const struct tm *tp); | |
237 char * | 236 char * |
238 zone_name (const struct tm *tp) | 237 zone_name (CONST struct tm *tp) |
239 { | 238 { |
240 char *timezone (); | 239 char *timezone (); |
241 struct timeval tv; | 240 struct timeval tv; |
242 struct timezone tz; | 241 struct timezone tz; |
243 | 242 |
250 results in STRING. | 249 results in STRING. |
251 Return the number of characters (not including terminating null) | 250 Return the number of characters (not including terminating null) |
252 that were put into STRING, or 0 if the length would have | 251 that were put into STRING, or 0 if the length would have |
253 exceeded MAX. */ | 252 exceeded MAX. */ |
254 | 253 |
255 size_t strftime (char *string, size_t max, const char *format, | 254 size_t strftime (char *string, size_t max, CONST char *format, |
256 const struct tm *tm); | 255 CONST struct tm *tm); |
257 | 256 |
258 size_t | 257 size_t |
259 strftime (char *string, size_t max, const char *format, const struct tm *tm) | 258 strftime (char *string, size_t max, CONST char *format, CONST struct tm *tm) |
260 { | 259 { |
261 enum padding pad; /* Type of padding to apply. */ | 260 enum padding pad; /* Type of padding to apply. */ |
262 size_t length = 0; /* Characters put in STRING so far. */ | 261 size_t length = 0; /* Characters put in STRING so far. */ |
263 | 262 |
264 for (; *format && length < max; ++format) | 263 for (; *format && length < max; ++format) |