Mercurial > hg > octave-nkf > gnulib-hg
changeset 10254:309ad548f542
getdate.y: factor out common actions
* lib/getdate.y (apply_relative_time, set_hhmmss): New functions.
Use them in place of open-coded actions.
author | Ondřej Vašík <ovasik@redhat.com> |
---|---|
date | Fri, 27 Jun 2008 17:37:40 +0200 |
parents | 6ab1c382f1a0 |
children | a945eb5a83fe |
files | ChangeLog lib/getdate.y |
diffstat | 2 files changed, 40 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-07-02 Ondřej Vašík <ovasik@redhat.com> + + 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 <simon@josefsson.org> Add self-test for getdate module.
--- a/lib/getdate.y +++ b/lib/getdate.y @@ -246,6 +246,31 @@ } } +/* Increment PC->rel by FACTOR * REL (FACTOR is 1 or -1). */ +static void +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; +} + +/* 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 = hour; + pc->minutes = minutes; + pc->seconds.tv_sec = sec; + pc->seconds.tv_nsec = nsec; +} + %} /* We want a reentrant parser, even if the TZ manipulation and the calls to @@ -313,7 +338,6 @@ | day { pc->days_seen++; } | rel - { pc->rels_seen = true; } | number | hybrid ; @@ -321,42 +345,29 @@ time: tUNUMBER tMERIDIAN { - pc->hour = $1.value; - pc->minutes = 0; - pc->seconds.tv_sec = 0; - pc->seconds.tv_nsec = 0; + set_hhmmss (pc, $1.value, 0, 0, 0); pc->meridian = $2; } | tUNUMBER ':' tUNUMBER o_merid { - pc->hour = $1.value; - pc->minutes = $3.value; - pc->seconds.tv_sec = 0; - pc->seconds.tv_nsec = 0; + set_hhmmss (pc, $1.value, $3.value, 0, 0); pc->meridian = $4; } | tUNUMBER ':' tUNUMBER tSNUMBER o_colon_minutes { - pc->hour = $1.value; - pc->minutes = $3.value; - pc->seconds.tv_sec = 0; - pc->seconds.tv_nsec = 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 { - pc->hour = $1.value; - pc->minutes = $3.value; - pc->seconds = $5; + set_hhmmss (pc, $1.value, $3.value, $5.tv_sec, $5.tv_nsec); pc->meridian = $6; } | tUNUMBER ':' tUNUMBER ':' unsigned_seconds tSNUMBER o_colon_minutes { - pc->hour = $1.value; - pc->minutes = $3.value; - pc->seconds = $5; + 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); @@ -381,14 +392,7 @@ { pc->time_zone = $1; } | tZONE relunit_snumber { pc->time_zone = $1; - pc->rel.ns += $2.ns; - pc->rel.seconds += $2.seconds; - pc->rel.minutes += $2.minutes; - pc->rel.hour += $2.hour; - pc->rel.day += $2.day; - pc->rel.month += $2.month; - pc->rel.year += $2.year; - pc->rels_seen = true; } + apply_relative_time (pc, $2, 1); } | tZONE tSNUMBER o_colon_minutes { pc->time_zone = $1 + time_zone_hhmm ($2, $3); } | tDAYZONE @@ -495,25 +499,9 @@ rel: relunit tAGO - { - pc->rel.ns -= $1.ns; - pc->rel.seconds -= $1.seconds; - pc->rel.minutes -= $1.minutes; - pc->rel.hour -= $1.hour; - pc->rel.day -= $1.day; - pc->rel.month -= $1.month; - pc->rel.year -= $1.year; - } + { apply_relative_time (pc, $1, -1); } | relunit - { - pc->rel.ns += $1.ns; - pc->rel.seconds += $1.seconds; - pc->rel.minutes += $1.minutes; - pc->rel.hour += $1.hour; - pc->rel.day += $1.day; - pc->rel.month += $1.month; - pc->rel.year += $1.year; - } + { apply_relative_time (pc, $1, 1); } ; relunit: @@ -600,14 +588,7 @@ /* Hybrid all-digit and relative offset, so that we accept e.g., "YYYYMMDD +N days" as well as "YYYYMMDD N days". */ digits_to_date_time (pc, $1); - pc->rel.ns += $2.ns; - pc->rel.seconds += $2.seconds; - pc->rel.minutes += $2.minutes; - pc->rel.hour += $2.hour; - pc->rel.day += $2.day; - pc->rel.month += $2.month; - pc->rel.year += $2.year; - pc->rels_seen = true; + apply_relative_time (pc, $2, 1); } ;