tmlocale.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* time conversion translation support
*/
#include <ast.h>
#include <cdt.h>
#include <iconv.h>
#include <mc.h>
#include <tm.h>
#include <ast_nl_types.h>
#include "lclib.h"
static struct
{
char* format;
char null[1];
} state;
/*
* this is unix dadgummit
*/
static int
{
{
b[TM_TIME] = "%H:%M:%S";
b[TM_DATE] = "%m/%d/%y";
b[TM_DEFAULT] = "%a %b %e %T %Z %Y";
return 1;
}
return 0;
}
/*
* fix up LC_TIME data after loading
*/
static void
{
register char** v;
register char** e;
register int n;
static int must[] =
{
};
standardized(li, b);
for (v = b, e = b + TM_NFORM; v < e; v++)
if (!*v)
for (n = 0; n < elementsof(must); n++)
if (!*b[must[n]])
for (n = 0; n < TM_NFORM; n++)
if (!*b[n])
{
}
else
}
#if _WINIX
#include <ast_windows.h>
typedef struct Map_s
{
int local;
} Map_t;
{
LOCALE_S1159, (TM_MERIDIAN+0),
LOCALE_SDAYNAME7, (TM_DAY+0),
LOCALE_SMONTHNAME1, (TM_MONTH+0),
};
#undef extern
/*
* convert ms word date spec w to posix strftime format f
* next char after f returned
* the caller already made sure f is big enough
*/
static char*
word2posix(register char* f, register char* w, int alternate)
{
register char* r;
register int c;
register int p;
register int n;
while (*w)
{
p = 0;
r = w;
while (*++w == *r);
if ((n = w - r) > 3 && alternate)
n--;
switch (*r)
{
case 'a':
case 'A':
w += 5;
w += 3;
c = 'p';
break;
case 'd':
switch (n)
{
case 1:
p = '-';
/*FALLTHROUGH*/
case 2:
c = 'd';
break;
case 3:
c = 'a';
break;
default:
c = 'A';
break;
}
break;
case 'h':
switch (n)
{
case 1:
p = '-';
/*FALLTHROUGH*/
default:
c = 'I';
break;
}
break;
case 'H':
switch (n)
{
case 1:
p = '-';
/*FALLTHROUGH*/
default:
c = 'H';
break;
}
break;
case 'M':
switch (n)
{
case 1:
p = '-';
/*FALLTHROUGH*/
case 2:
c = 'm';
break;
case 3:
c = 'b';
break;
default:
c = 'B';
break;
}
break;
case 'm':
switch (n)
{
case 1:
p = '-';
/*FALLTHROUGH*/
default:
c = 'M';
break;
}
break;
case 's':
switch (n)
{
case 1:
p = '-';
/*FALLTHROUGH*/
default:
c = 'S';
break;
}
break;
case 'y':
switch (n)
{
case 1:
p = '-';
/*FALLTHROUGH*/
case 2:
c = 'y';
break;
default:
c = 'Y';
break;
}
break;
case '\'':
if (n & 1)
for (w = r + 1; *w; *f++ = *w++)
if (*w == '\'')
{
w++;
break;
}
continue;
case '%':
while (r < w)
{
*f++ = *r++;
*f++ = *r++;
}
continue;
default:
while (r < w)
*f++ = *r++;
continue;
}
*f++ = '%';
if (p)
*f++ = '-';
*f++ = c;
}
*f++ = 0;
return f;
}
/*
* load the native LC_TIME data for the current locale
*/
static void
{
register char* s;
register char* t;
register char** b;
register int n;
register int m;
register int i;
int nt;
int ns;
int nl;
int clock_24;
int leading_0;
char buf[256];
for (i = 0; i < elementsof(map); i++)
return;
s = (char*)(b + TM_NFORM);
for (i = 0; i < elementsof(map); i++)
{
goto bad;
s += m;
}
if (!standardized(li, b))
{
/*
* synthesize TM_TIME format from the ms word template
*/
goto bad;
goto bad;
goto bad;
b[TM_TIME] = s;
*s++ = '%';
if (!leading_0)
*s++ = '-';
for (t = buf; *s = *t++; s++);
*s++ = '%';
if (!leading_0)
*s++ = '-';
*s++ = 'M';
for (t = buf; *s = *t++; s++);
*s++ = '%';
if (!leading_0)
*s++ = '-';
*s++ = 'S';
*s++ = 0;
/*
* synthesize TM_DATE format
*/
goto bad;
b[TM_DATE] = s;
/*
* synthesize TM_DEFAULT format
*/
goto bad;
b[TM_DEFAULT] = s;
}
/*
* done
*/
return;
bad:
free(b);
}
#else
#if _lib_nl_langinfo && _hdr_langinfo
#if _hdr_nl_types
#include <nl_types.h>
#endif
#include <langinfo.h>
typedef struct Map_s
{
int native;
int local;
} Map_t;
{
AM_STR, (TM_MERIDIAN+0),
ABDAY_1, (TM_DAY_ABBREV+0),
ABMON_1, (TM_MONTH_ABBREV+0),
#ifdef _DATE_FMT
#else
#endif
#ifdef ERA
#endif
#ifdef ALT_DIGITS
#endif
};
static void
{
register char* s;
register char* t;
register char** b;
register int n;
register int i;
n = 0;
for (i = 0; i < elementsof(map); i++)
{
n += strlen(t) + 1;
}
return;
s = (char*)(b + TM_NFORM);
for (i = 0; i < elementsof(map); i++)
{
while (*s++ = *t++);
}
}
#else
#define native_lc_time(li) ((li->data=(void*)(tm_info.format=tm_data.format)),(tm_info.deformat=tm_info.format[TM_DEFAULT]))
#endif
#endif
/*
* load the LC_TIME data for the current locale
*/
static void
{
register char* s;
register char** b;
register char** v;
register char** e;
unsigned char* u;
ssize_t n;
{
return;
}
{
tp = 0;
{
{
{
}
}
if (!tp)
}
{
v = b;
e = b + TM_NFORM;
s = (char*)e;
{
s[n] = '\n';
while (v < e)
{
*v++ = s;
if (!(s = strchr(s, '\n')))
break;
*s++ = 0;
}
}
else
free(b);
}
if (tp)
}
else
}
/*
* check that tm_info.format matches the current locale
*/
char**
tmlocale(void)
{
{
}
}