From 228a52df6fbe55b20039947ab11297e75162e903 Mon Sep 17 00:00:00 2001 From: ache Date: Tue, 30 Nov 1999 08:05:09 +0000 Subject: Fix %C handling Use locale for %c Add %+ Add %Ex and %OB --- lib/libc/stdtime/strptime.c | 66 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/lib/libc/stdtime/strptime.c b/lib/libc/stdtime/strptime.c index f9a3855..d92430a 100644 --- a/lib/libc/stdtime/strptime.c +++ b/lib/libc/stdtime/strptime.c @@ -90,6 +90,7 @@ _strptime(const char *buf, const char *fmt, struct tm *tm) const char *ptr; int i, len; + int Ealternative, Oalternative; ptr = fmt; while (*ptr != 0) { @@ -107,6 +108,9 @@ _strptime(const char *buf, const char *fmt, struct tm *tm) continue; } + Ealternative = 0; + Oalternative = 0; +label: c = *ptr++; switch (c) { case 0: @@ -115,14 +119,28 @@ _strptime(const char *buf, const char *fmt, struct tm *tm) return 0; break; - case 'C': + case '+': buf = _strptime(buf, Locale->date_fmt, tm); if (buf == 0) return 0; break; + case 'C': + if (!isdigit((unsigned char)*buf)) + return 0; + + for (i = 0; *buf != 0 && isdigit((unsigned char)*buf); buf++) { + i *= 10; + i += *buf - '0'; + } + if (i < 19) + return 0; + + tm->tm_year = i * 100 - 1900; + break; + case 'c': - buf = _strptime(buf, "%x %X", tm); + buf = _strptime(buf, Locale->c_fmt, tm); if (buf == 0) return 0; break; @@ -133,6 +151,14 @@ _strptime(const char *buf, const char *fmt, struct tm *tm) return 0; break; + case 'E': + Ealternative++; + goto label; + + case 'O': + Oalternative++; + goto label; + case 'R': buf = _strptime(buf, "%H:%M", tm); if (buf == 0) @@ -158,7 +184,7 @@ _strptime(const char *buf, const char *fmt, struct tm *tm) break; case 'x': - buf = _strptime(buf, Locale->x_fmt, tm); + buf = _strptime(buf, Ealternative ? Locale->Ex_fmt : Locale->x_fmt, tm); if (buf == 0) return 0; break; @@ -338,17 +364,29 @@ _strptime(const char *buf, const char *fmt, struct tm *tm) case 'b': case 'h': for (i = 0; i < asizeof(Locale->month); i++) { - len = strlen(Locale->month[i]); - if (strncasecmp(buf, - Locale->month[i], - len) == 0) - break; - - len = strlen(Locale->mon[i]); - if (strncasecmp(buf, - Locale->mon[i], - len) == 0) - break; + if (Oalternative) { + if (c == 'B') { + len = strlen(Locale->alt_month[i]); + if (strncasecmp(buf, + Locale->alt_month[i], + len) == 0) + break; + } + } else { + if (c == 'B') { + len = strlen(Locale->month[i]); + if (strncasecmp(buf, + Locale->month[i], + len) == 0) + break; + } else { + len = strlen(Locale->mon[i]); + if (strncasecmp(buf, + Locale->mon[i], + len) == 0) + break; + } + } } if (i == asizeof(Locale->month)) return 0; -- cgit v1.1