No code changes, removed tabs from source file.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67278 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Dimitri Schoolwerth
2011-03-22 14:06:20 +00:00
parent 6853f5fbf9
commit e4e0d4702b

View File

@@ -60,13 +60,13 @@ time_t __cdecl mktime(struct tm *t)
// // // //
///////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////
#define IN_NONE 0 #define IN_NONE 0
#define IN_SOME 1 #define IN_SOME 1
#define IN_THIS 2 #define IN_THIS 2
#define IN_ALL 3 #define IN_ALL 3
#define CHAR_BIT 8 #define CHAR_BIT 8
#define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
#define TYPE_SIGNED(type) (((type) -1) < 0) #define TYPE_SIGNED(type) (((type) -1) < 0)
#define INT_STRLEN_MAXIMUM(type) \ #define INT_STRLEN_MAXIMUM(type) \
@@ -74,448 +74,448 @@ time_t __cdecl mktime(struct tm *t)
#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
#define MONSPERYEAR 12 #define MONSPERYEAR 12
#define DAYSPERWEEK 7 #define DAYSPERWEEK 7
#define TM_YEAR_BASE 1900 #define TM_YEAR_BASE 1900
#define HOURSPERDAY 24 #define HOURSPERDAY 24
#define DAYSPERNYEAR 365 #define DAYSPERNYEAR 365
#define DAYSPERLYEAR 366 #define DAYSPERLYEAR 366
static char wildabbr[] = "WILDABBR"; static char wildabbr[] = "WILDABBR";
char * tzname[2] = { char * tzname[2] = {
wildabbr, wildabbr,
wildabbr wildabbr
}; };
#define Locale (&C_time_locale) #define Locale (&C_time_locale)
struct lc_time_T { struct lc_time_T {
const char * mon[MONSPERYEAR]; const char * mon[MONSPERYEAR];
const char * month[MONSPERYEAR]; const char * month[MONSPERYEAR];
const char * wday[DAYSPERWEEK]; const char * wday[DAYSPERWEEK];
const char * weekday[DAYSPERWEEK]; const char * weekday[DAYSPERWEEK];
const char * X_fmt; const char * X_fmt;
const char * x_fmt; const char * x_fmt;
const char * c_fmt; const char * c_fmt;
const char * am; const char * am;
const char * pm; const char * pm;
const char * date_fmt; const char * date_fmt;
}; };
static const struct lc_time_T C_time_locale = { static const struct lc_time_T C_time_locale = {
{ {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
}, { }, {
"January", "February", "March", "April", "May", "June", "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" "July", "August", "September", "October", "November", "December"
}, { }, {
"Sun", "Mon", "Tue", "Wed", "Sun", "Mon", "Tue", "Wed",
"Thu", "Fri", "Sat" "Thu", "Fri", "Sat"
}, { }, {
"Sunday", "Monday", "Tuesday", "Wednesday", "Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday" "Thursday", "Friday", "Saturday"
}, },
/* X_fmt */ /* X_fmt */
"%H:%M:%S", "%H:%M:%S",
/* /*
** x_fmt ** x_fmt
** C99 requires this format. ** C99 requires this format.
** Using just numbers (as here) makes Quakers happier; ** Using just numbers (as here) makes Quakers happier;
** it's also compatible with SVR4. ** it's also compatible with SVR4.
*/ */
"%m/%d/%y", "%m/%d/%y",
/* /*
** c_fmt ** c_fmt
** C99 requires this format. ** C99 requires this format.
** Previously this code used "%D %X", but we now conform to C99. ** Previously this code used "%D %X", but we now conform to C99.
** Note that ** Note that
** "%a %b %d %H:%M:%S %Y" ** "%a %b %d %H:%M:%S %Y"
** is used by Solaris 2.3. ** is used by Solaris 2.3.
*/ */
"%a %b %e %T %Y", "%a %b %e %T %Y",
/* am */ /* am */
"AM", "AM",
/* pm */ /* pm */
"PM", "PM",
/* date_fmt */ /* date_fmt */
"%a %b %e %H:%M:%S %Z %Y" "%a %b %e %H:%M:%S %Z %Y"
}; };
static char * static char *
_add(const char * str, char * pt, const char * const ptlim) _add(const char * str, char * pt, const char * const ptlim)
{ {
while (pt < ptlim && (*pt = *str++) != '\0') while (pt < ptlim && (*pt = *str++) != '\0')
++pt; ++pt;
return pt; return pt;
} }
static char * static char *
_conv(const int n, const char * const format, char * const pt, const char * const ptlim) _conv(const int n, const char * const format, char * const pt, const char * const ptlim)
{ {
char buf[INT_STRLEN_MAXIMUM(int) + 1]; char buf[INT_STRLEN_MAXIMUM(int) + 1];
(void) _snprintf(buf, sizeof buf, format, n); (void) _snprintf(buf, sizeof buf, format, n);
return _add(buf, pt, ptlim); return _add(buf, pt, ptlim);
} }
static char * static char *
_fmt(const char * format, const struct tm * const t, char * pt, const char * const ptlim, int * warnp) _fmt(const char * format, const struct tm * const t, char * pt, const char * const ptlim, int * warnp)
{ {
for ( ; *format; ++format) { for ( ; *format; ++format) {
if (*format == '%') { if (*format == '%') {
label: label:
switch (*++format) { switch (*++format) {
case '\0': case '\0':
--format; --format;
break; break;
case 'A': case 'A':
pt = _add((t->tm_wday < 0 || pt = _add((t->tm_wday < 0 ||
t->tm_wday >= DAYSPERWEEK) ? t->tm_wday >= DAYSPERWEEK) ?
"?" : Locale->weekday[t->tm_wday], "?" : Locale->weekday[t->tm_wday],
pt, ptlim); pt, ptlim);
continue; continue;
case 'a': case 'a':
pt = _add((t->tm_wday < 0 || pt = _add((t->tm_wday < 0 ||
t->tm_wday >= DAYSPERWEEK) ? t->tm_wday >= DAYSPERWEEK) ?
"?" : Locale->wday[t->tm_wday], "?" : Locale->wday[t->tm_wday],
pt, ptlim); pt, ptlim);
continue; continue;
case 'B': case 'B':
pt = _add((t->tm_mon < 0 || pt = _add((t->tm_mon < 0 ||
t->tm_mon >= MONSPERYEAR) ? t->tm_mon >= MONSPERYEAR) ?
"?" : Locale->month[t->tm_mon], "?" : Locale->month[t->tm_mon],
pt, ptlim); pt, ptlim);
continue; continue;
case 'b': case 'b':
case 'h': case 'h':
pt = _add((t->tm_mon < 0 || pt = _add((t->tm_mon < 0 ||
t->tm_mon >= MONSPERYEAR) ? t->tm_mon >= MONSPERYEAR) ?
"?" : Locale->mon[t->tm_mon], "?" : Locale->mon[t->tm_mon],
pt, ptlim); pt, ptlim);
continue; continue;
case 'C': case 'C':
/* /*
** %C used to do a... ** %C used to do a...
** _fmt("%a %b %e %X %Y", t); ** _fmt("%a %b %e %X %Y", t);
** ...whereas now POSIX 1003.2 calls for ** ...whereas now POSIX 1003.2 calls for
** something completely different. ** something completely different.
** (ado, 1993-05-24) ** (ado, 1993-05-24)
*/ */
pt = _conv((t->tm_year + TM_YEAR_BASE) / 100, pt = _conv((t->tm_year + TM_YEAR_BASE) / 100,
"%02d", pt, ptlim); "%02d", pt, ptlim);
continue; continue;
case 'c': case 'c':
{ {
int warn2 = IN_SOME; int warn2 = IN_SOME;
pt = _fmt(Locale->c_fmt, t, pt, ptlim, warnp); pt = _fmt(Locale->c_fmt, t, pt, ptlim, warnp);
if (warn2 == IN_ALL) if (warn2 == IN_ALL)
warn2 = IN_THIS; warn2 = IN_THIS;
if (warn2 > *warnp) if (warn2 > *warnp)
*warnp = warn2; *warnp = warn2;
} }
continue; continue;
case 'D': case 'D':
pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp); pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp);
continue; continue;
case 'd': case 'd':
pt = _conv(t->tm_mday, "%02d", pt, ptlim); pt = _conv(t->tm_mday, "%02d", pt, ptlim);
continue; continue;
case 'E': case 'E':
case 'O': case 'O':
/* /*
** C99 locale modifiers. ** C99 locale modifiers.
** The sequences ** The sequences
** %Ec %EC %Ex %EX %Ey %EY ** %Ec %EC %Ex %EX %Ey %EY
** %Od %oe %OH %OI %Om %OM ** %Od %oe %OH %OI %Om %OM
** %OS %Ou %OU %OV %Ow %OW %Oy ** %OS %Ou %OU %OV %Ow %OW %Oy
** are supposed to provide alternate ** are supposed to provide alternate
** representations. ** representations.
*/ */
goto label; goto label;
case 'e': case 'e':
pt = _conv(t->tm_mday, "%2d", pt, ptlim); pt = _conv(t->tm_mday, "%2d", pt, ptlim);
continue; continue;
case 'F': case 'F':
pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp); pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp);
continue; continue;
case 'H': case 'H':
pt = _conv(t->tm_hour, "%02d", pt, ptlim); pt = _conv(t->tm_hour, "%02d", pt, ptlim);
continue; continue;
case 'I': case 'I':
pt = _conv((t->tm_hour % 12) ? pt = _conv((t->tm_hour % 12) ?
(t->tm_hour % 12) : 12, (t->tm_hour % 12) : 12,
"%02d", pt, ptlim); "%02d", pt, ptlim);
continue; continue;
case 'j': case 'j':
pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim); pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim);
continue; continue;
case 'k': case 'k':
/* /*
** This used to be... ** This used to be...
** _conv(t->tm_hour % 12 ? ** _conv(t->tm_hour % 12 ?
** t->tm_hour % 12 : 12, 2, ' '); ** t->tm_hour % 12 : 12, 2, ' ');
** ...and has been changed to the below to ** ...and has been changed to the below to
** match SunOS 4.1.1 and Arnold Robbins' ** match SunOS 4.1.1 and Arnold Robbins'
** strftime version 3.0. That is, "%k" and ** strftime version 3.0. That is, "%k" and
** "%l" have been swapped. ** "%l" have been swapped.
** (ado, 1993-05-24) ** (ado, 1993-05-24)
*/ */
pt = _conv(t->tm_hour, "%2d", pt, ptlim); pt = _conv(t->tm_hour, "%2d", pt, ptlim);
continue; continue;
#ifdef KITCHEN_SINK #ifdef KITCHEN_SINK
case 'K': case 'K':
/* /*
** After all this time, still unclaimed! ** After all this time, still unclaimed!
*/ */
pt = _add("kitchen sink", pt, ptlim); pt = _add("kitchen sink", pt, ptlim);
continue; continue;
#endif /* defined KITCHEN_SINK */ #endif /* defined KITCHEN_SINK */
case 'l': case 'l':
/* /*
** This used to be... ** This used to be...
** _conv(t->tm_hour, 2, ' '); ** _conv(t->tm_hour, 2, ' ');
** ...and has been changed to the below to ** ...and has been changed to the below to
** match SunOS 4.1.1 and Arnold Robbin's ** match SunOS 4.1.1 and Arnold Robbin's
** strftime version 3.0. That is, "%k" and ** strftime version 3.0. That is, "%k" and
** "%l" have been swapped. ** "%l" have been swapped.
** (ado, 1993-05-24) ** (ado, 1993-05-24)
*/ */
pt = _conv((t->tm_hour % 12) ? pt = _conv((t->tm_hour % 12) ?
(t->tm_hour % 12) : 12, (t->tm_hour % 12) : 12,
"%2d", pt, ptlim); "%2d", pt, ptlim);
continue; continue;
case 'M': case 'M':
pt = _conv(t->tm_min, "%02d", pt, ptlim); pt = _conv(t->tm_min, "%02d", pt, ptlim);
continue; continue;
case 'm': case 'm':
pt = _conv(t->tm_mon + 1, "%02d", pt, ptlim); pt = _conv(t->tm_mon + 1, "%02d", pt, ptlim);
continue; continue;
case 'n': case 'n':
pt = _add("\n", pt, ptlim); pt = _add("\n", pt, ptlim);
continue; continue;
case 'p': case 'p':
pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ? pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ?
Locale->pm : Locale->pm :
Locale->am, Locale->am,
pt, ptlim); pt, ptlim);
continue; continue;
case 'R': case 'R':
pt = _fmt("%H:%M", t, pt, ptlim, warnp); pt = _fmt("%H:%M", t, pt, ptlim, warnp);
continue; continue;
case 'r': case 'r':
pt = _fmt("%I:%M:%S %p", t, pt, ptlim, warnp); pt = _fmt("%I:%M:%S %p", t, pt, ptlim, warnp);
continue; continue;
case 'S': case 'S':
pt = _conv(t->tm_sec, "%02d", pt, ptlim); pt = _conv(t->tm_sec, "%02d", pt, ptlim);
continue; continue;
case 's': case 's':
{ {
struct tm tm; struct tm tm;
char buf[INT_STRLEN_MAXIMUM( char buf[INT_STRLEN_MAXIMUM(
time_t) + 1]; time_t) + 1];
time_t mkt; time_t mkt;
tm = *t; tm = *t;
mkt = mktime(&tm); mkt = mktime(&tm);
if (TYPE_SIGNED(time_t)) if (TYPE_SIGNED(time_t))
(void) _snprintf(buf, sizeof buf, (void) _snprintf(buf, sizeof buf,
"%ld", (long) mkt); "%ld", (long) mkt);
else (void) _snprintf(buf, sizeof buf, else (void) _snprintf(buf, sizeof buf,
"%lu", (unsigned long) mkt); "%lu", (unsigned long) mkt);
pt = _add(buf, pt, ptlim); pt = _add(buf, pt, ptlim);
} }
continue; continue;
case 'T': case 'T':
pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp); pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp);
continue; continue;
case 't': case 't':
pt = _add("\t", pt, ptlim); pt = _add("\t", pt, ptlim);
continue; continue;
case 'U': case 'U':
pt = _conv((t->tm_yday + DAYSPERWEEK - pt = _conv((t->tm_yday + DAYSPERWEEK -
t->tm_wday) / DAYSPERWEEK, t->tm_wday) / DAYSPERWEEK,
"%02d", pt, ptlim); "%02d", pt, ptlim);
continue; continue;
case 'u': case 'u':
/* /*
** From Arnold Robbins' strftime version 3.0: ** From Arnold Robbins' strftime version 3.0:
** "ISO 8601: Weekday as a decimal number ** "ISO 8601: Weekday as a decimal number
** [1 (Monday) - 7]" ** [1 (Monday) - 7]"
** (ado, 1993-05-24) ** (ado, 1993-05-24)
*/ */
pt = _conv((t->tm_wday == 0) ? pt = _conv((t->tm_wday == 0) ?
DAYSPERWEEK : t->tm_wday, DAYSPERWEEK : t->tm_wday,
"%d", pt, ptlim); "%d", pt, ptlim);
continue; continue;
case 'V': /* ISO 8601 week number */ case 'V': /* ISO 8601 week number */
case 'G': /* ISO 8601 year (four digits) */ case 'G': /* ISO 8601 year (four digits) */
case 'g': /* ISO 8601 year (two digits) */ case 'g': /* ISO 8601 year (two digits) */
{ {
int year; int year;
int yday; int yday;
int wday; int wday;
int w; int w;
year = t->tm_year + TM_YEAR_BASE; year = t->tm_year + TM_YEAR_BASE;
yday = t->tm_yday; yday = t->tm_yday;
wday = t->tm_wday; wday = t->tm_wday;
for ( ; ; ) { for ( ; ; ) {
int len; int len;
int bot; int bot;
int top; int top;
len = isleap(year) ? len = isleap(year) ?
DAYSPERLYEAR : DAYSPERLYEAR :
DAYSPERNYEAR; DAYSPERNYEAR;
/* /*
** What yday (-3 ... 3) does ** What yday (-3 ... 3) does
** the ISO year begin on? ** the ISO year begin on?
*/ */
bot = ((yday + 11 - wday) % bot = ((yday + 11 - wday) %
DAYSPERWEEK) - 3; DAYSPERWEEK) - 3;
/* /*
** What yday does the NEXT ** What yday does the NEXT
** ISO year begin on? ** ISO year begin on?
*/ */
top = bot - top = bot -
(len % DAYSPERWEEK); (len % DAYSPERWEEK);
if (top < -3) if (top < -3)
top += DAYSPERWEEK; top += DAYSPERWEEK;
top += len; top += len;
if (yday >= top) { if (yday >= top) {
++year; ++year;
w = 1; w = 1;
break; break;
} }
if (yday >= bot) { if (yday >= bot) {
w = 1 + ((yday - bot) / w = 1 + ((yday - bot) /
DAYSPERWEEK); DAYSPERWEEK);
break; break;
} }
--year; --year;
yday += isleap(year) ? yday += isleap(year) ?
DAYSPERLYEAR : DAYSPERLYEAR :
DAYSPERNYEAR; DAYSPERNYEAR;
} }
if (*format == 'V') if (*format == 'V')
pt = _conv(w, "%02d", pt = _conv(w, "%02d",
pt, ptlim); pt, ptlim);
else if (*format == 'g') { else if (*format == 'g') {
*warnp = IN_ALL; *warnp = IN_ALL;
pt = _conv(year % 100, "%02d", pt = _conv(year % 100, "%02d",
pt, ptlim); pt, ptlim);
} else pt = _conv(year, "%04d", } else pt = _conv(year, "%04d",
pt, ptlim); pt, ptlim);
} }
continue; continue;
case 'v': case 'v':
pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp); pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp);
continue; continue;
case 'W': case 'W':
pt = _conv((t->tm_yday + DAYSPERWEEK - pt = _conv((t->tm_yday + DAYSPERWEEK -
(t->tm_wday ? (t->tm_wday ?
(t->tm_wday - 1) : (t->tm_wday - 1) :
(DAYSPERWEEK - 1))) / DAYSPERWEEK, (DAYSPERWEEK - 1))) / DAYSPERWEEK,
"%02d", pt, ptlim); "%02d", pt, ptlim);
continue; continue;
case 'w': case 'w':
pt = _conv(t->tm_wday, "%d", pt, ptlim); pt = _conv(t->tm_wday, "%d", pt, ptlim);
continue; continue;
case 'X': case 'X':
pt = _fmt(Locale->X_fmt, t, pt, ptlim, warnp); pt = _fmt(Locale->X_fmt, t, pt, ptlim, warnp);
continue; continue;
case 'x': case 'x':
{ {
int warn2 = IN_SOME; int warn2 = IN_SOME;
pt = _fmt(Locale->x_fmt, t, pt, ptlim, &warn2); pt = _fmt(Locale->x_fmt, t, pt, ptlim, &warn2);
if (warn2 == IN_ALL) if (warn2 == IN_ALL)
warn2 = IN_THIS; warn2 = IN_THIS;
if (warn2 > *warnp) if (warn2 > *warnp)
*warnp = warn2; *warnp = warn2;
} }
continue; continue;
case 'y': case 'y':
*warnp = IN_ALL; *warnp = IN_ALL;
pt = _conv((t->tm_year + TM_YEAR_BASE) % 100, pt = _conv((t->tm_year + TM_YEAR_BASE) % 100,
"%02d", pt, ptlim); "%02d", pt, ptlim);
continue; continue;
case 'Y': case 'Y':
pt = _conv(t->tm_year + TM_YEAR_BASE, "%04d", pt = _conv(t->tm_year + TM_YEAR_BASE, "%04d",
pt, ptlim); pt, ptlim);
continue; continue;
case 'Z': case 'Z':
if (t->tm_isdst >= 0) if (t->tm_isdst >= 0)
pt = _add(tzname[t->tm_isdst != 0], pt = _add(tzname[t->tm_isdst != 0],
pt, ptlim); pt, ptlim);
/* /*
** C99 says that %Z must be replaced by the ** C99 says that %Z must be replaced by the
** empty string if the time zone is not ** empty string if the time zone is not
** determinable. ** determinable.
*/ */
continue; continue;
case 'z': case 'z':
{ {
int diff = -timezone; int diff = -timezone;
char const * sign; char const * sign;
if (diff < 0) { if (diff < 0) {
sign = "-"; sign = "-";
diff = -diff; diff = -diff;
} else sign = "+"; } else sign = "+";
pt = _add(sign, pt, ptlim); pt = _add(sign, pt, ptlim);
diff /= 60; diff /= 60;
pt = _conv((diff/60)*100 + diff%60, pt = _conv((diff/60)*100 + diff%60,
"%04d", pt, ptlim); "%04d", pt, ptlim);
} }
continue; continue;
case '+': case '+':
pt = _fmt(Locale->date_fmt, t, pt, ptlim, pt = _fmt(Locale->date_fmt, t, pt, ptlim,
warnp); warnp);
continue; continue;
case '%': case '%':
default: default:
break; break;
} }
} }
if (pt == ptlim) if (pt == ptlim)
break; break;
*pt++ = *format; *pt++ = *format;
} }
return pt; return pt;
} }
size_t size_t
strftime(char * const s, const size_t maxsize, const char *format, const struct tm * const t) strftime(char * const s, const size_t maxsize, const char *format, const struct tm * const t)
{ {
char * p; char *p;
int warn; int warn;
//tzset(); //tzset();
warn = IN_NONE; warn = IN_NONE;
p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn); p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn);
if (p == s + maxsize) { if (p == s + maxsize) {
if (maxsize > 0) if (maxsize > 0)
s[maxsize - 1] = '\0'; s[maxsize - 1] = '\0';
return 0; return 0;
} }
*p = '\0'; *p = '\0';
return p - s; return p - s;
} }
extern "C" extern "C"