Ondřej Vašík [EMAIL PROTECTED] wrote:
...
From 9eb2711cd03b3825e36cff33e7e7fccbbfc504d1 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Ond=C5=99ej=20Va=C5=A1=C3=ADk?= [EMAIL PROTECTED]
Date: Fri, 27 Jun 2008 17:37:40 +0200
Subject: [PATCH] *lib/getdate.y: Factorize duplicate code for relative time
offset and hhmmss times.
I'm looking at this factorization-only patch, now.
Here are the changes I'm merging with yours:
- add a ChangeLog entry
- don't add trailing blanks
- don't add lines longer than 80
- adjust indentation and formatting to match existing style
- renamed the new functions
diff --git a/ChangeLog b/ChangeLog
index b9076e2..b5d4f05 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-07-02 Ondřej Vašík [EMAIL PROTECTED]
+
+ getdate.y: factor out common actions
+ * lib/getdate.y (apply_relative_time, set_hhmmss): New functions.
+ Use them in place of open-coded actions.
+
2008-07-01 Simon Josefsson [EMAIL PROTECTED]
Add self-test for getdate module.
diff --git a/lib/getdate.y b/lib/getdate.y
index b9566a5..9171147 100644
--- a/lib/getdate.y
+++ b/lib/getdate.y
@@ -246,28 +246,29 @@ digits_to_date_time (parser_control *pc, textint text_int)
}
}
-/* Extract relative time multiplied by factor into *pc */
+/* Increment PC-rel by FACTOR * REL (FACTOR is 1 or -1). */
static void
-extract_relative_time (parser_control *pc, relative_time rel, int factor)
+apply_relative_time (parser_control *pc, relative_time rel, int factor)
{
- pc-rel.ns += factor*rel.ns;
- pc-rel.seconds += factor*rel.seconds;
- pc-rel.minutes += factor*rel.minutes;
- pc-rel.hour += factor*rel.hour;
- pc-rel.day += factor*rel.day;
- pc-rel.month += factor*rel.month;
- pc-rel.year += factor*rel.year;
- pc-rels_seen = true;
-}
-
-/* Extract hours, minutes, seconds and nanoseconds from arguments into *pc */
-static void
-extract_hhmmss (parser_control *pc, long int ho, long int mi, time_t sec, long
int nsec)
+ pc-rel.ns += factor * rel.ns;
+ pc-rel.seconds += factor * rel.seconds;
+ pc-rel.minutes += factor * rel.minutes;
+ pc-rel.hour += factor * rel.hour;
+ pc-rel.day += factor * rel.day;
+ pc-rel.month += factor * rel.month;
+ pc-rel.year += factor * rel.year;
+ pc-rels_seen = true;
+}
+
+/* Set PC- hour, minutes, seconds and nanoseconds members from arguments. */
+static void
+set_hhmmss (parser_control *pc, long int hour, long int minutes,
+ time_t sec, long int nsec)
{
- pc-hour = ho;
- pc-minutes = mi;
- pc-seconds.tv_sec = sec;
- pc-seconds.tv_nsec = nsec;
+ pc-hour = hour;
+ pc-minutes = minutes;
+ pc-seconds.tv_sec = sec;
+ pc-seconds.tv_nsec = nsec;
}
%}
@@ -344,29 +345,29 @@ item:
time:
tUNUMBER tMERIDIAN
{
- extract_hhmmss (pc, $1.value, 0, 0, 0);
+ set_hhmmss (pc, $1.value, 0, 0, 0);
pc-meridian = $2;
}
| tUNUMBER ':' tUNUMBER o_merid
{
- extract_hhmmss (pc, $1.value, $3.value, 0, 0);
+ set_hhmmss (pc, $1.value, $3.value, 0, 0);
pc-meridian = $4;
}
| tUNUMBER ':' tUNUMBER tSNUMBER o_colon_minutes
{
- extract_hhmmss (pc, $1.value, $3.value, 0, 0);
+ set_hhmmss (pc, $1.value, $3.value, 0, 0);
pc-meridian = MER24;
pc-zones_seen++;
pc-time_zone = time_zone_hhmm ($4, $5);
}
| tUNUMBER ':' tUNUMBER ':' unsigned_seconds o_merid
{
- extract_hhmmss (pc, $1.value, $3.value, $5.tv_sec, $5.tv_nsec);
+ set_hhmmss (pc, $1.value, $3.value, $5.tv_sec, $5.tv_nsec);
pc-meridian = $6;
}
| tUNUMBER ':' tUNUMBER ':' unsigned_seconds tSNUMBER o_colon_minutes
{
- extract_hhmmss (pc, $1.value, $3.value, $5.tv_sec, $5.tv_nsec);
+ set_hhmmss (pc, $1.value, $3.value, $5.tv_sec, $5.tv_nsec);
pc-meridian = MER24;
pc-zones_seen++;
pc-time_zone = time_zone_hhmm ($6, $7);
@@ -391,7 +392,7 @@ zone:
{ pc-time_zone = $1; }
| tZONE relunit_snumber
{ pc-time_zone = $1;
- extract_relative_time (pc, $2, 1); }
+ apply_relative_time (pc, $2, 1); }
| tZONE tSNUMBER o_colon_minutes
{ pc-time_zone = $1 + time_zone_hhmm ($2, $3); }
| tDAYZONE
@@ -498,9 +499,9 @@ date:
rel:
relunit tAGO
- {extract_relative_time (pc, $1, -1); }
+ { apply_relative_time (pc, $1, -1); }
| relunit
- { extract_relative_time (pc, $1, 1); }
+ { apply_relative_time (pc, $1, 1); }
;
relunit:
@@ -587,7 +588,7 @@ hybrid:
/* Hybrid all-digit and relative offset, so that we accept e.g.,
MMDD +N days as well as MMDD N days. */
digits_to_date_time (pc, $1);
- extract_relative_time (pc, $2, 1);
+ apply_relative_time (pc, $2, 1);
}
;
___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils