/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
-#include <crtdll/string.h>
-#include <crtdll/time.h>
-#include <crtdll/stdlib.h>
-#include <crtdll/wchar.h>
+#include <msvcrt/string.h>
+#include <msvcrt/time.h>
+#include <msvcrt/stdlib.h>
+#include <msvcrt/wchar.h>
+
#define TM_YEAR_BASE 1900
-static const char *afmt[] = {
+static const char* afmt[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
};
-static const char *Afmt[] = {
+static const char* Afmt[] = {
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday",
};
-static const char *bfmt[] = {
+static const char* bfmt[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
"Oct", "Nov", "Dec",
};
-static const char *Bfmt[] = {
+static const char* Bfmt[] = {
"January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December",
};
static size_t gsize;
-static char *pt;
+static char* pt;
+
-static int
-_add(const char *str)
+static int _add(const char* str)
{
for (;; ++pt, --gsize)
{
}
}
-static int
-_conv(int n, int digits, char pad)
+static int _conv(int n, int digits, char pad)
{
static char buf[10];
- char *p;
+ char* p;
for (p = buf + sizeof(buf) - 2; n > 0 && p > buf; n /= 10, --digits)
*p-- = n % 10 + '0';
return _add(++p);
}
-static size_t
-_fmt(const char *format, const struct tm *t)
+static size_t _fmt(const char* format, const struct tm* t)
{
for (; *format; ++format)
{
if (*format == '%') {
- if (*(format+1) == '#' ) {format++;}
+ if (*(format+1) == '#') {format++;}
- switch(*++format)
- {
+ switch(*++format) {
case '\0':
--format;
break;
return 0;
continue;
case 'I':
- if (!_conv(t->tm_hour % 12 ?
- t->tm_hour % 12 : 12, 2, '0'))
+ if (!_conv(t->tm_hour % 12 ? t->tm_hour % 12 : 12, 2, '0'))
return 0;
continue;
case 'j':
return 0;
continue;
case 'l':
- if (!_conv(t->tm_hour % 12 ?
- t->tm_hour % 12 : 12, 2, ' '))
+ if (!_conv(t->tm_hour % 12 ? t->tm_hour % 12 : 12, 2, ' '))
return 0;
continue;
case 'M':
return 0;
continue;
case 'U':
- if (!_conv((t->tm_yday + 7 - t->tm_wday) / 7,
- 2, '0'))
+ if (!_conv((t->tm_yday + 7 - t->tm_wday) / 7, 2, '0'))
return 0;
continue;
case 'W':
- if (!_conv((t->tm_yday + 7 -
- (t->tm_wday ? (t->tm_wday - 1) : 6))
- / 7, 2, '0'))
+ if (!_conv((t->tm_yday + 7 - (t->tm_wday ? (t->tm_wday - 1) : 6)) / 7, 2, '0'))
return 0;
continue;
case 'w':
return 0;
continue;
case 'y':
- if (!_conv((t->tm_year + TM_YEAR_BASE)
- % 100, 2, '0'))
+ if (!_conv((t->tm_year + TM_YEAR_BASE) % 100, 2, '0'))
return 0;
continue;
case 'Y':
return 0;
}
-size_t
-wcsftime(wchar_t *s, size_t maxsize, const wchar_t *format, const struct tm *t)
+size_t wcsftime(wchar_t* s, size_t maxsize, const wchar_t* format, const struct tm* t)
{
- char *x;
- char *f;
+ char* x;
+ char* f;
int i,j;
x = malloc(maxsize);
j = wcslen(format);
f = malloc(j+1);
- for(i=0;i<j;i++)
+ for (i = 0; i < j; i++)
f[i] = (char)*format;
f[i] = 0;
pt = x;
if ((gsize = maxsize) < 1)
return 0;
- if (_fmt(f, t))
- {
+ if (_fmt(f, t)) {
*pt = '\0';
free(f);
- for(i=0;i<maxsize;i++)
+ for (i = 0; i < maxsize;i ++)
s[i] = (wchar_t)x[i];
s[i] = 0;
free(x);
return maxsize - gsize;
}
- for(i=0;i<maxsize;i++)
+ for (i = 0; i < maxsize; i++)
s[i] = (wchar_t)x[i];
s[i] = 0;
free(f);