[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] maint: reformat parse-datetime debugging code
From: |
Pádraig Brady |
Subject: |
[PATCH] maint: reformat parse-datetime debugging code |
Date: |
Sat, 21 Jan 2017 01:16:15 +0000 |
* lib/parse-datetime.y (parse_datetime2): Use consistent spacing,
remove redundant line continuation characters,
remove redundant if (pc.parse_datetime_debug) checks.
Avoid a redundant call to get_effective_timezone() when not debugging.
---
lib/parse-datetime.y | 99 +++++++++++++++++++++++++---------------------------
1 file changed, 47 insertions(+), 52 deletions(-)
diff --git a/lib/parse-datetime.y b/lib/parse-datetime.y
index c604be6..ae7ca03 100644
--- a/lib/parse-datetime.y
+++ b/lib/parse-datetime.y
@@ -404,7 +404,7 @@ debug_print_current_time (const char* item, parser_control
*pc)
char tmp[100] = {0};
int space = 0; /* if true, add space delimiter */
- if (!pc->parse_datetime_debug)
+ if (! pc->parse_datetime_debug)
return;
/* no newline, more items printed below */
@@ -505,18 +505,18 @@ debug_print_relative_time (const char* item, const
parser_control *pc)
{
int space = 0; /* if true, add space delimiter */
- if (!pc->parse_datetime_debug)
+ if (! pc->parse_datetime_debug)
return;
/* no newline, more items printed below */
dbg_printf (_("parsed %s part: "), item);
if (pc->rel.year==0 && pc->rel.month==0 && pc->rel.day==0
- && pc->rel.hour==0 && pc->rel.minutes==00 && pc->rel.seconds == 0
+ && pc->rel.hour==0 && pc->rel.minutes==0 && pc->rel.seconds == 0
&& pc->rel.ns==0)
{
/* Special case: relative time of this/today/now */
- fputs (_("today/this/now\n"),stderr);
+ fputs (_("today/this/now\n"), stderr);
return ;
}
@@ -800,7 +800,7 @@ date:
if (4 <= $1.digits)
{
if (pc->parse_datetime_debug)
- dbg_printf (_("warning: value %ld has %"PRIuMAX" digits. " \
+ dbg_printf (_("warning: value %ld has %"PRIuMAX" digits. "
"Assuming YYYY/MM/DD\n"), $1.value, $1.digits);
pc->year = $1;
@@ -810,7 +810,7 @@ date:
else
{
if (pc->parse_datetime_debug)
- dbg_printf (_("warning: value %ld has less than 4 digits. " \
+ dbg_printf (_("warning: value %ld has less than 4 digits. "
"Assuming MM/DD/YY[YY]\n"), $1.value);
pc->month = $1.value;
@@ -1672,7 +1672,7 @@ debug_mktime_not_ok (struct tm const *tm0, struct tm
const *tm1,
const bool dst_shift = eq_sec && eq_min && !eq_hour
&& eq_mday && eq_month && eq_year;
- if (!pc->parse_datetime_debug)
+ if (! pc->parse_datetime_debug)
return;
dbg_printf (_("error: invalid date/time value:\n"));
@@ -1836,7 +1836,7 @@ parse_datetime2 (struct timespec *result, char const *p,
pc.dsts_seen = 0;
pc.zones_seen = 0;
pc.year_seen = 0;
- pc.parse_datetime_debug = (flags & PARSE_DATETIME_DEBUG)!=0;
+ pc.parse_datetime_debug = (flags & PARSE_DATETIME_DEBUG) != 0;
pc.debug_dates_seen = 0;
pc.debug_days_seen = 0;
pc.debug_times_seen = 0;
@@ -1905,7 +1905,8 @@ parse_datetime2 (struct timespec *result, char const *p,
pc.local_time_zone_table[1].name = NULL;
}
- pc.debug_default_input_timezone = get_effective_timezone ();
+ if (pc.parse_datetime_debug)
+ pc.debug_default_input_timezone = get_effective_timezone ();
if (yyparse (&pc) != 0)
{
@@ -1938,14 +1939,14 @@ parse_datetime2 (struct timespec *result, char const *p,
tz = pc.time_zone;
strncpy (dbg_tm, _("parsed date/time string"), sizeof (dbg_tm)-1);
}
- else if ((tz_env = getenv("TZ")))
+ else if ((tz_env = getenv ("TZ")))
{
if (tz_was_altered)
{
- snprintf (dbg_tm, sizeof(dbg_tm), _("TZ=\"%s\" in date string"),
+ snprintf (dbg_tm, sizeof (dbg_tm), _("TZ=\"%s\" in date string"),
tz_env);
}
- else if (STREQ(tz_env,"UTC0"))
+ else if (STREQ (tz_env,"UTC0"))
{
/* Special case: using 'date -u' simply set TZ=UTC0 */
strncpy (dbg_tm, _("TZ=UTC0 environment value or -u"),
@@ -1975,10 +1976,8 @@ parse_datetime2 (struct timespec *result, char const *p,
sizeof (dbg_tm) - strlen (dbg_tm) - 1);
}
- if (pc.parse_datetime_debug)
- dbg_printf (_("input timezone: %+03d:%02d (set from %s)\n"),
- (int)(tz/60), abs ((int)tz)%60, dbg_tm);
-
+ dbg_printf (_("input timezone: %+03d:%02d (set from %s)\n"),
+ (int)(tz/60), abs ((int)tz)%60, dbg_tm);
}
if (pc.timespec_seen)
@@ -2107,10 +2106,10 @@ parse_datetime2 (struct timespec *result, char const *p,
if (Start == (time_t) -1)
{
if (pc.parse_datetime_debug)
- dbg_printf (_("error: day '%s' (day ordinal=%ld number=%d) "
\
+ dbg_printf (_("error: day '%s' (day ordinal=%ld number=%d) "
"resulted in an invalid date: '%s'\n"),
str_days (&pc,dbg_ord,sizeof (dbg_ord)),
- pc.day_ordinal,pc.day_number,
+ pc.day_ordinal, pc.day_number,
debug_strfdatetime (&tm, &pc, dbg_tm,
sizeof (dbg_tm)));
@@ -2128,15 +2127,15 @@ parse_datetime2 (struct timespec *result, char const *p,
{
if (!pc.dates_seen && !pc.days_seen)
dbg_printf (_("using current date as starting value: '%s'\n"),
- debug_strfdate (&tm,dbg_tm,sizeof (dbg_tm)));
+ debug_strfdate (&tm, dbg_tm, sizeof (dbg_tm)));
if (pc.days_seen && pc.dates_seen)
- dbg_printf (_("warning: day (%s) ignored when explicit dates " \
+ dbg_printf (_("warning: day (%s) ignored when explicit dates "
"are given\n"),
- str_days (&pc,dbg_ord,sizeof (dbg_ord)));
+ str_days (&pc, dbg_ord, sizeof (dbg_ord)));
dbg_printf (_("starting date/time: '%s'\n"),
- debug_strfdatetime (&tm, &pc, dbg_tm,sizeof (dbg_tm)));
+ debug_strfdatetime (&tm, &pc, dbg_tm, sizeof (dbg_tm)));
}
/* Add relative date. */
@@ -2144,13 +2143,13 @@ parse_datetime2 (struct timespec *result, char const *p,
{
if (pc.parse_datetime_debug)
{
- if ((pc.rel.year != 0 || pc.rel.month !=0) && tm.tm_mday!=15)
- dbg_printf (_("warning: when adding relative months/years, " \
- "it is recommended to specify the 15th of the " \
- "months\n"));
+ if ((pc.rel.year != 0 || pc.rel.month !=0) && tm.tm_mday != 15)
+ dbg_printf (_("warning: when adding relative months/years, "
+ "it is recommended to specify the 15th of the "
+ "month\n"));
- if (pc.rel.day != 0 && tm.tm_hour!=12)
- dbg_printf (_("warning: when adding relative days, " \
+ if (pc.rel.day != 0 && tm.tm_hour != 12)
+ dbg_printf (_("warning: when adding relative days, "
"it is recommended to specify 12:00pm\n"));
}
@@ -2178,7 +2177,7 @@ parse_datetime2 (struct timespec *result, char const *p,
if (Start == (time_t) -1)
{
if (pc.parse_datetime_debug)
- dbg_printf(_("error: adding relative date resulted " \
+ dbg_printf(_("error: adding relative date resulted "
"in an invalid date: '%s'\n"),
debug_strfdatetime (&tm, &pc, dbg_tm,
sizeof (dbg_tm)));
@@ -2188,7 +2187,7 @@ parse_datetime2 (struct timespec *result, char const *p,
if (pc.parse_datetime_debug)
{
- dbg_printf (_("after date adjustment " \
+ dbg_printf (_("after date adjustment "
"(%+ld years, %+ld months, %+ld days),\n"),
pc.rel.year, pc.rel.month, pc.rel.day);
dbg_printf (_(" new date/time = '%s'\n"),
@@ -2210,7 +2209,7 @@ parse_datetime2 (struct timespec *result, char const *p,
mktime(&tm).
*/
if ((tm0.tm_isdst!=-1) && (tm.tm_isdst != tm0.tm_isdst))
- dbg_printf (_("warning: daylight saving time changed after " \
+ dbg_printf (_("warning: daylight saving time changed after "
"date adjustment\n"));
/* warn if the user did not ask to adjust days but mday changed,
@@ -2229,7 +2228,7 @@ parse_datetime2 (struct timespec *result, char const *p,
|| ((pc.rel.day==0) && (pc.rel.month==0)
&& (tm.tm_mon != month)))
{
- dbg_printf (_("warning: month/year adjustment resulted in "\
+ dbg_printf (_("warning: month/year adjustment resulted in "
"shifted dates:\n"));
dbg_printf (_(" adjusted Y M D: %04d %02d %02d\n"),
year+1900, month+1, day);
@@ -2308,7 +2307,7 @@ parse_datetime2 (struct timespec *result, char const *p,
| (t5 != t4))
{
if (pc.parse_datetime_debug)
- dbg_printf (_("error: adding relative time caused an " \
+ dbg_printf (_("error: adding relative time caused an "
"overflow\n"));
goto fail;
@@ -2317,7 +2316,7 @@ parse_datetime2 (struct timespec *result, char const *p,
if (pc.parse_datetime_debug
&& (pc.rel.hour | pc.rel.minutes | pc.rel.seconds | pc.rel.ns))
{
- dbg_printf (_("after time adjustment (%+ld hours, " \
+ dbg_printf (_("after time adjustment (%+ld hours, "
"%+ld minutes, %+ld seconds, %+ld ns),\n"),
pc.rel.hour,pc.rel.minutes,pc.rel.seconds,pc.rel.ns);
dbg_printf (_(" new time = %ld epoch-seconds\n"),t5);
@@ -2336,7 +2335,7 @@ parse_datetime2 (struct timespec *result, char const *p,
*/
struct tm const *lmt = localtime (&t5);
if ((tm.tm_isdst!=-1) && (tm.tm_isdst != lmt->tm_isdst))
- dbg_printf (_("warning: daylight saving time changed after " \
+ dbg_printf (_("warning: daylight saving time changed after "
"time adjustment\n"));
}
@@ -2362,10 +2361,10 @@ parse_datetime2 (struct timespec *result, char const *p,
const char* tz_src;
const char* tz_env;
- if ((tz_env = getenv("TZ")))
+ if ((tz_env = getenv ("TZ")))
{
/* Special case: using 'date -u' simply set TZ=UTC0 */
- if (STREQ(tz_env,"UTC0"))
+ if (STREQ (tz_env,"UTC0"))
{
tz_src = _("TZ=UTC0 environment value or -u");
}
@@ -2381,23 +2380,19 @@ parse_datetime2 (struct timespec *result, char const *p,
tz_src = _("system default");
}
- if (pc.parse_datetime_debug)
- {
- dbg_printf (_("output timezone: %+03d:%02d (set from %s)\n"),
- (int)(otz/60), abs ((int)otz)%60, tz_src);
-
+ dbg_printf (_("output timezone: %+03d:%02d (set from %s)\n"),
+ (int)(otz/60), abs ((int)otz)%60, tz_src);
- dbg_printf (_("final: %ld.%09ld (epoch-seconds)\n"),
- result->tv_sec,result->tv_nsec);
+ dbg_printf (_("final: %ld.%09ld (epoch-seconds)\n"),
+ result->tv_sec,result->tv_nsec);
- struct tm const *gmt = gmtime (&result->tv_sec);
- dbg_printf (_("final: %s (UTC0)\n"),
- debug_strfdatetime (gmt, NULL, dbg_tm, sizeof (dbg_tm)));
- struct tm const *lmt = localtime (&result->tv_sec);
- dbg_printf (_("final: %s (output timezone TZ=%+03d:%02d)\n"),
- debug_strfdatetime (lmt, NULL, dbg_tm, sizeof (dbg_tm)),
- (int)(otz/60), abs ((int)otz)%60);
- }
+ struct tm const *gmt = gmtime (&result->tv_sec);
+ dbg_printf (_("final: %s (UTC0)\n"),
+ debug_strfdatetime (gmt, NULL, dbg_tm, sizeof (dbg_tm)));
+ struct tm const *lmt = localtime (&result->tv_sec);
+ dbg_printf (_("final: %s (output timezone TZ=%+03d:%02d)\n"),
+ debug_strfdatetime (lmt, NULL, dbg_tm, sizeof (dbg_tm)),
+ (int)(otz/60), abs ((int)otz)%60);
}
return ok;
--
2.5.5
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] maint: reformat parse-datetime debugging code,
Pádraig Brady <=