Relax local FreeBSD restrictions on 3 chars abbrev. name length and %c format

since they not allows POSIXly legal locale data. Currently, if relaxed form
POSIXly legal locale data will be used right now, some programs will be broken,
but it means that either locale data or programs must be fixed, not the library.

Introduce non-standard md_order (month/day order) locale field to be used later
via nl_langinfo(). Currently %EF and %Ef emulated using this field, but they
planned for remove in future in favour of nl_langinfo() test field.

Implement %F per POSIX
This commit is contained in:
Andrey A. Chernov 2001-03-18 11:58:15 +00:00
parent 989efc86f5
commit faeb1b822a
5 changed files with 37 additions and 37 deletions

View File

@ -85,25 +85,17 @@ as follows:-
is replaced by national representation of the full weekday name.
.It Cm %a
is replaced by national representation of
the abbreviated weekday name, where the abbreviation
is the first three characters.
the abbreviated weekday name.
.It Cm \&%B
is replaced by national representation of the full month name.
.It Cm %b
is replaced by national representation of
the abbreviated month name, where the abbreviation is
the first three characters.
the abbreviated month name.
.It Cm \&%C
is replaced by (year / 100) as decimal number; single
digits are preceded by a zero.
.It Cm %c
is replaced by national representation of time and date.
The format is similar to that produced by
.Xr ctime 3
and is
equivalent to "%a %Ef %T %Y".
It also implies the
"3+1+6+1+8+1+4" format of output.
.It Cm \&%D
is equivalent to
.Dq Li %m/%d/%y .
@ -126,6 +118,9 @@ and %OB to represent alternative months names
.It Cm %e
is replaced by the day of month as a decimal number (1-31); single
digits are preceded by a blank.
.It Cm \&%F
is equivalent to
.Dq Li %Y-%m-%d .
.It Cm \&%G
is replaced by a year as a decimal number with century.
This year is the one that contains the greater part of

View File

@ -123,7 +123,6 @@ label:
"%02d", pt, ptlim);
continue;
case 'c':
/* NOTE: c_fmt is hardcoded in timelocal.c */
pt = _fmt(tptr->c_fmt, t, pt, ptlim);
continue;
case 'D':
@ -162,12 +161,17 @@ label:
case 'f':
if (!Ealternative)
break;
pt = _fmt(tptr->Ef_fmt, t, pt, ptlim);
pt = _fmt(*(tptr->md_order) == 'd' ?
"%e %b" : "%b %e",
t, pt, ptlim);
continue;
case 'F':
if (!Ealternative)
break;
pt = _fmt(tptr->EF_fmt, t, pt, ptlim);
pt = _fmt("%Y-%m-%d", t, pt, ptlim);
else
pt = _fmt(*(tptr->md_order) == 'd' ?
"%e %B" : "%B %e",
t, pt, ptlim);
continue;
case 'H':
pt = _conv(t->tm_hour, "%02d", pt, ptlim);

View File

@ -141,7 +141,6 @@ label:
break;
case 'c':
/* NOTE: c_fmt is hardcoded in timelocal.c */
buf = _strptime(buf, tptr->c_fmt, tm);
if (buf == 0)
return 0;
@ -166,10 +165,22 @@ label:
goto label;
case 'F':
if (!Ealternative)
buf = _strptime(buf, "%Y-%m-%d", tm);
else
buf = _strptime(buf,
*(tptr->md_order) == 'd' ?
"%e %B" : "%B %e", tm);
if (buf == 0)
return 0;
break;
case 'f':
if (!Ealternative)
break;
buf = _strptime(buf, (c == 'f') ? tptr->Ef_fmt : tptr->EF_fmt, tm);
buf = _strptime(buf,
*(tptr->md_order) == 'd' ? "%e %b" : "%b %e",
tm);
if (buf == 0)
return 0;
break;

View File

@ -36,9 +36,7 @@ static struct lc_time_T _time_locale;
static int _time_using_locale;
static char * time_locale_buf;
#define LCTIME_SIZE_FULL (sizeof(struct lc_time_T) / sizeof(char *))
#define LCTIME_SIZE_MIN \
(offsetof(struct lc_time_T, ampm_fmt) / sizeof(char *))
#define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *))
static const struct lc_time_T _C_time_locale = {
{
@ -70,7 +68,7 @@ static const struct lc_time_T _C_time_locale = {
/*
** c_fmt (ctime-compatible)
*/
"%a %Ef %T %Y",
"%a %b %e %T %Y",
/* am */
"AM",
@ -79,22 +77,20 @@ static const struct lc_time_T _C_time_locale = {
"PM",
/* date_fmt */
"%a %Ef %X %Z %Y",
"%a %b %e %X %Z %Y",
/* alt_month
** Standalone motnhs forms for %OB
*/
{
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
},
/* Ef_fmt
** To determine short months / day order
/* md_order
** Month / day order in dates
*/
"%b %e",
/* EF_fmt
** To determine long months / day order
*/
"%B %e",
"md",
/* ampm_fmt
** To determine 12-hour clock format time (empty, if N/A)
@ -114,15 +110,10 @@ __time_load_locale(const char *name) {
int ret;
_time_locale.ampm_fmt = _C_time_locale.ampm_fmt;
ret = __part_load_locale(name, &_time_using_locale,
time_locale_buf, "LC_TIME",
LCTIME_SIZE_FULL, LCTIME_SIZE_MIN,
LCTIME_SIZE, LCTIME_SIZE,
(const char **)&_time_locale);
/* XXX: always overwrite for ctime format parsing compatibility */
_time_locale.c_fmt = _C_time_locale.c_fmt;
return (ret);
}

View File

@ -45,8 +45,7 @@ struct lc_time_T {
const char * pm;
const char * date_fmt;
const char * alt_month[12];
const char * Ef_fmt;
const char * EF_fmt;
const char * md_order;
const char * ampm_fmt;
};