Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/time KNF and additional comments
details: https://anonhg.NetBSD.org/src/rev/4c5a8c7cff41
branches: trunk
changeset: 339409:4c5a8c7cff41
user: ginsbach <ginsbach%NetBSD.org@localhost>
date: Mon Jul 20 14:37:11 2015 +0000
description:
KNF and additional comments
diffstat:
lib/libc/time/strptime.c | 28 +++++++++++++++++++++-------
1 files changed, 21 insertions(+), 7 deletions(-)
diffs (91 lines):
diff -r e7ce3ef40b9e -r 4c5a8c7cff41 lib/libc/time/strptime.c
--- a/lib/libc/time/strptime.c Mon Jul 20 13:13:31 2015 +0000
+++ b/lib/libc/time/strptime.c Mon Jul 20 14:37:11 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: strptime.c,v 1.45 2015/07/15 13:54:38 ginsbach Exp $ */
+/* $NetBSD: strptime.c,v 1.46 2015/07/20 14:37:11 ginsbach Exp $ */
/*-
* Copyright (c) 1997, 1998, 2005, 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: strptime.c,v 1.45 2015/07/15 13:54:38 ginsbach Exp $");
+__RCSID("$NetBSD: strptime.c,v 1.46 2015/07/20 14:37:11 ginsbach Exp $");
#endif
#include "namespace.h"
@@ -50,6 +50,10 @@
__weak_alias(strptime_l, _strptime_l)
#endif
+static const u_char *conv_num(const unsigned char *, int *, uint, uint);
+static const u_char *find_string(const u_char *, int *, const char * const *,
+ const char * const *, int);
+
#define _TIME_LOCALE(loc) \
((_TimeLocale *)((loc)->part_impl[(size_t)LC_TIME]))
@@ -83,12 +87,14 @@
"EDT", "CDT", "MDT", "PDT", "\0\0\0"
};
-static const u_char *conv_num(const unsigned char *, int *, uint, uint);
-static const u_char *find_string(const u_char *, int *, const char * const *,
- const char * const *, int);
-
+/*
+ * Table to determine the ordinal date for the start of a month.
+ * Ref: http://en.wikipedia.org/wiki/ISO_week_date
+ */
static const int start_of_month[2][13] = {
+ /* non-leap year */
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
+ /* leap year */
{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
};
@@ -586,11 +592,13 @@
if (!HAVE_YDAY(state) && HAVE_YEAR(state)) {
if (HAVE_MON(state) && HAVE_MDAY(state)) {
+ /* calculate day of year (ordinal date) */
tm->tm_yday = start_of_month[isleap_sum(tm->tm_year,
TM_YEAR_BASE)][tm->tm_mon] + (tm->tm_mday - 1);
state |= S_YDAY;
} else if (day_offset != -1) {
- /* Set the date to the first Sunday (or Monday)
+ /*
+ * Set the date to the first Sunday (or Monday)
* of the specified week of the year.
*/
if (!HAVE_WDAY(state)) {
@@ -607,7 +615,9 @@
if (HAVE_YDAY(state) && HAVE_YEAR(state)) {
int isleap;
+
if (!HAVE_MON(state)) {
+ /* calculate month of day of year */
i = 0;
isleap = isleap_sum(tm->tm_year, TM_YEAR_BASE);
while (tm->tm_yday >= start_of_month[isleap][i])
@@ -620,13 +630,17 @@
tm->tm_mon = i - 1;
state |= S_MON;
}
+
if (!HAVE_MDAY(state)) {
+ /* calculate day of month */
isleap = isleap_sum(tm->tm_year, TM_YEAR_BASE);
tm->tm_mday = tm->tm_yday -
start_of_month[isleap][tm->tm_mon] + 1;
state |= S_MDAY;
}
+
if (!HAVE_WDAY(state)) {
+ /* calculate day of week */
i = 0;
week_offset = first_wday_of(tm->tm_year);
while (i++ <= tm->tm_yday) {
Home |
Main Index |
Thread Index |
Old Index