Add %Ex extension to determine "%e %b" or "%b %e" order

Separate alternative for O and E cases
This commit is contained in:
Andrey A. Chernov 1999-11-30 07:33:37 +00:00
parent 8e0788736e
commit 11cd0d3241
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=53940
3 changed files with 22 additions and 8 deletions

View File

@ -75,10 +75,12 @@ _fmt(format, t, pt, ptlim)
char *pt;
const char *const ptlim;
{
int alternative;
int Ealternative, Oalternative;
for ( ; *format; ++format) {
if (*format == '%') {
alternative = 0;
Ealternative = 0;
Oalternative = 0;
label:
switch (*++format) {
case '\0':
@ -96,7 +98,7 @@ _fmt(format, t, pt, ptlim)
continue;
case 'B':
pt = _add((t->tm_mon < 0 || t->tm_mon > 11) ?
"?" : (alternative ? Locale->alt_month :
"?" : (Oalternative ? Locale->alt_month :
Locale->month)[t->tm_mon],
pt, ptlim);
continue;
@ -127,6 +129,8 @@ _fmt(format, t, pt, ptlim)
pt = _conv(t->tm_mday, "%02d", pt, ptlim);
continue;
case 'E':
Ealternative++;
goto label;
case 'O':
/*
** POSIX locale extensions, a la
@ -139,7 +143,7 @@ _fmt(format, t, pt, ptlim)
** representations.
** (ado, 5/24/93)
*/
alternative = 1;
Oalternative++;
goto label;
case 'e':
pt = _conv(t->tm_mday, "%2d", pt, ptlim);
@ -357,7 +361,7 @@ _fmt(format, t, pt, ptlim)
pt = _fmt(Locale->X_fmt, t, pt, ptlim);
continue;
case 'x':
pt = _fmt(Locale->x_fmt, t, pt, ptlim);
pt = _fmt(Ealternative ? Locale->Ex_fmt : Locale->x_fmt, t, pt, ptlim);
continue;
case 'y':
pt = _conv((t->tm_year + TM_YEAR_BASE) % 100,

View File

@ -46,6 +46,8 @@ int _time_using_locale;
#define LCTIME_SIZE_FULL (sizeof(struct lc_time_T) / sizeof(char *))
#define LCTIME_SIZE_1 \
(offsetof(struct lc_time_T, alt_month[0]) / sizeof(char *))
#define LCTIME_SIZE_2 \
(offsetof(struct lc_time_T, Ex_fmt) / sizeof(char *))
const struct lc_time_T _C_time_locale = {
{
@ -80,7 +82,7 @@ const struct lc_time_T _C_time_locale = {
** "%a %b %d %H:%M:%S %Y"
** is used by Solaris 2.3.
*/
"%a %b %e %X %Y",
"%a %Ex %X %Y",
/* am */
"AM",
@ -89,12 +91,17 @@ const struct lc_time_T _C_time_locale = {
"PM",
/* date_fmt */
"%a %b %e %X %Z %Y",
"%a %Ex %X %Z %Y",
{
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
}
},
/* Ex_fmt
** To determine months / day order
*/
"%b %e"
};
@ -173,6 +180,8 @@ __time_load_locale(const char *name)
num_lines = split_lines(p, plim);
if (num_lines >= LCTIME_SIZE_FULL)
num_lines = LCTIME_SIZE_FULL;
else if (num_lines >= LCTIME_SIZE_2)
num_lines = LCTIME_SIZE_2;
else if (num_lines >= LCTIME_SIZE_1)
num_lines = LCTIME_SIZE_1;
else

View File

@ -42,6 +42,7 @@ struct lc_time_T {
const char * pm;
const char * date_fmt;
const char * alt_month[12];
const char * Ex_fmt;
};
extern struct lc_time_T _time_localebuf;