Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libutil make this thread-safe. We could use localtime_tz...
details: https://anonhg.NetBSD.org/src/rev/ab52902d72ce
branches: trunk
changeset: 760016:ab52902d72ce
user: christos <christos%NetBSD.org@localhost>
date: Fri Dec 24 03:37:37 2010 +0000
description:
make this thread-safe. We could use localtime_tz and make it even better,
but not now.
diffstat:
lib/libutil/parsedate.y | 432 ++++++++++++++++++++++++-----------------------
1 files changed, 218 insertions(+), 214 deletions(-)
diffs (truncated from 778 to 300 lines):
diff -r 760f206ccceb -r ab52902d72ce lib/libutil/parsedate.y
--- a/lib/libutil/parsedate.y Fri Dec 24 02:58:20 2010 +0000
+++ b/lib/libutil/parsedate.y Fri Dec 24 03:37:37 2010 +0000
@@ -62,32 +62,26 @@
} MERIDIAN;
-/*
-** Global variables. We could get rid of most of these by using a good
-** union as the yacc stack. (This routine was originally written before
-** yacc had the %union construct.) Maybe someday; right now we only use
-** the %union very rarely.
-*/
-static const char *yyInput;
-static DSTMODE yyDSTmode;
-static time_t yyDayOrdinal;
-static time_t yyDayNumber;
-static int yyHaveDate;
-static int yyHaveDay;
-static int yyHaveRel;
-static int yyHaveTime;
-static int yyHaveZone;
-static time_t yyTimezone;
-static time_t yyDay;
-static time_t yyHour;
-static time_t yyMinutes;
-static time_t yyMonth;
-static time_t yySeconds;
-static time_t yyYear;
-static MERIDIAN yyMeridian;
-static time_t yyRelMonth;
-static time_t yyRelSeconds;
-
+struct dateinfo {
+ DSTMODE yyDSTmode;
+ time_t yyDayOrdinal;
+ time_t yyDayNumber;
+ int yyHaveDate;
+ int yyHaveDay;
+ int yyHaveRel;
+ int yyHaveTime;
+ int yyHaveZone;
+ time_t yyTimezone;
+ time_t yyDay;
+ time_t yyHour;
+ time_t yyMinutes;
+ time_t yyMonth;
+ time_t yySeconds;
+ time_t yyYear;
+ MERIDIAN yyMeridian;
+ time_t yyRelMonth;
+ time_t yyRelSeconds;
+};
%}
%union {
@@ -102,6 +96,11 @@
%type <Number> tSEC_UNIT tSNUMBER tUNUMBER tZONE
%type <Meridian> tMERIDIAN o_merid
+%parse-param { struct dateinfo *param }
+%parse-param { const char **yyInput }
+%lex-param { const char **yyInput }
+%pure-parser
+
%%
spec : /* NULL */
@@ -109,43 +108,43 @@
;
item : time {
- yyHaveTime++;
+ param->yyHaveTime++;
}
| zone {
- yyHaveZone++;
+ param->yyHaveZone++;
}
| date {
- yyHaveDate++;
+ param->yyHaveDate++;
}
| day {
- yyHaveDay++;
+ param->yyHaveDay++;
}
| rel {
- yyHaveRel++;
+ param->yyHaveRel++;
}
| cvsstamp {
- yyHaveTime++;
- yyHaveDate++;
- yyHaveZone++;
+ param->yyHaveTime++;
+ param->yyHaveDate++;
+ param->yyHaveZone++;
}
| epochdate {
- yyHaveTime++;
- yyHaveDate++;
- yyHaveZone++;
+ param->yyHaveTime++;
+ param->yyHaveDate++;
+ param->yyHaveZone++;
}
| number
;
cvsstamp: tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER {
- yyYear = $1;
- if (yyYear < 100) yyYear += 1900;
- yyMonth = $3;
- yyDay = $5;
- yyHour = $7;
- yyMinutes = $9;
- yySeconds = $11;
- yyDSTmode = DSToff;
- yyTimezone = 0;
+ param->yyYear = $1;
+ if (param->yyYear < 100) param->yyYear += 1900;
+ param->yyMonth = $3;
+ param->yyDay = $5;
+ param->yyHour = $7;
+ param->yyMinutes = $9;
+ param->yySeconds = $11;
+ param->yyDSTmode = DSToff;
+ param->yyTimezone = 0;
}
;
@@ -153,205 +152,205 @@
time_t when = $2;
struct tm tmbuf;
if (gmtime_r(&when, &tmbuf) != NULL) {
- yyYear = tmbuf.tm_year + 1900;
- yyMonth = tmbuf.tm_mon + 1;
- yyDay = tmbuf.tm_mday;
+ param->yyYear = tmbuf.tm_year + 1900;
+ param->yyMonth = tmbuf.tm_mon + 1;
+ param->yyDay = tmbuf.tm_mday;
- yyHour = tmbuf.tm_hour;
- yyMinutes = tmbuf.tm_min;
- yySeconds = tmbuf.tm_sec;
+ param->yyHour = tmbuf.tm_hour;
+ param->yyMinutes = tmbuf.tm_min;
+ param->yySeconds = tmbuf.tm_sec;
} else {
- yyYear = EPOCH;
- yyMonth = 1;
- yyDay = 1;
+ param->yyYear = EPOCH;
+ param->yyMonth = 1;
+ param->yyDay = 1;
- yyHour = 0;
- yyMinutes = 0;
- yySeconds = 0;
+ param->yyHour = 0;
+ param->yyMinutes = 0;
+ param->yySeconds = 0;
}
- yyDSTmode = DSToff;
- yyTimezone = 0;
+ param->yyDSTmode = DSToff;
+ param->yyTimezone = 0;
}
;
time : tUNUMBER tMERIDIAN {
- yyHour = $1;
- yyMinutes = 0;
- yySeconds = 0;
- yyMeridian = $2;
+ param->yyHour = $1;
+ param->yyMinutes = 0;
+ param->yySeconds = 0;
+ param->yyMeridian = $2;
}
| tUNUMBER ':' tUNUMBER o_merid {
- yyHour = $1;
- yyMinutes = $3;
- yySeconds = 0;
- yyMeridian = $4;
+ param->yyHour = $1;
+ param->yyMinutes = $3;
+ param->yySeconds = 0;
+ param->yyMeridian = $4;
}
| tUNUMBER ':' tUNUMBER tSNUMBER {
- yyHour = $1;
- yyMinutes = $3;
- yyMeridian = MER24;
- yyDSTmode = DSToff;
- yyTimezone = - ($4 % 100 + ($4 / 100) * 60);
+ param->yyHour = $1;
+ param->yyMinutes = $3;
+ param->yyMeridian = MER24;
+ param->yyDSTmode = DSToff;
+ param->yyTimezone = - ($4 % 100 + ($4 / 100) * 60);
}
| tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid {
- yyHour = $1;
- yyMinutes = $3;
- yySeconds = $5;
- yyMeridian = $6;
+ param->yyHour = $1;
+ param->yyMinutes = $3;
+ param->yySeconds = $5;
+ param->yyMeridian = $6;
}
| tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER {
- yyHour = $1;
- yyMinutes = $3;
- yySeconds = $5;
- yyMeridian = MER24;
- yyDSTmode = DSToff;
- yyTimezone = - ($6 % 100 + ($6 / 100) * 60);
+ param->yyHour = $1;
+ param->yyMinutes = $3;
+ param->yySeconds = $5;
+ param->yyMeridian = MER24;
+ param->yyDSTmode = DSToff;
+ param->yyTimezone = - ($6 % 100 + ($6 / 100) * 60);
}
| tUNUMBER ':' tUNUMBER ':' tUNUMBER '.' tUNUMBER {
- yyHour = $1;
- yyMinutes = $3;
- yySeconds = $5;
- yyMeridian = MER24;
- yyDSTmode = DSToff;
+ param->yyHour = $1;
+ param->yyMinutes = $3;
+ param->yySeconds = $5;
+ param->yyMeridian = MER24;
+ param->yyDSTmode = DSToff;
/* XXX: Do nothing with millis */
-/* yyTimezone = ($7 % 100 + ($7 / 100) * 60); */
+/* param->yyTimezone = ($7 % 100 + ($7 / 100) * 60); */
}
;
zone : tZONE {
- yyTimezone = $1;
- yyDSTmode = DSToff;
+ param->yyTimezone = $1;
+ param->yyDSTmode = DSToff;
}
| tDAYZONE {
- yyTimezone = $1;
- yyDSTmode = DSTon;
+ param->yyTimezone = $1;
+ param->yyDSTmode = DSTon;
}
|
tZONE tDST {
- yyTimezone = $1;
- yyDSTmode = DSTon;
+ param->yyTimezone = $1;
+ param->yyDSTmode = DSTon;
}
;
day : tDAY {
- yyDayOrdinal = 1;
- yyDayNumber = $1;
+ param->yyDayOrdinal = 1;
+ param->yyDayNumber = $1;
}
| tDAY ',' {
- yyDayOrdinal = 1;
- yyDayNumber = $1;
+ param->yyDayOrdinal = 1;
+ param->yyDayNumber = $1;
}
| tUNUMBER tDAY {
- yyDayOrdinal = $1;
- yyDayNumber = $2;
+ param->yyDayOrdinal = $1;
+ param->yyDayNumber = $2;
}
;
date : tUNUMBER '/' tUNUMBER {
- yyMonth = $1;
- yyDay = $3;
+ param->yyMonth = $1;
+ param->yyDay = $3;
}
| tUNUMBER '/' tUNUMBER '/' tUNUMBER {
if ($1 >= 100) {
- yyYear = $1;
- yyMonth = $3;
- yyDay = $5;
+ param->yyYear = $1;
+ param->yyMonth = $3;
+ param->yyDay = $5;
} else {
Home |
Main Index |
Thread Index |
Old Index