summaryrefslogtreecommitdiffstats
path: root/generic/tclGetDate.y
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclGetDate.y')
-rw-r--r--generic/tclGetDate.y186
1 files changed, 90 insertions, 96 deletions
diff --git a/generic/tclGetDate.y b/generic/tclGetDate.y
index 1da7684..551b1ed 100644
--- a/generic/tclGetDate.y
+++ b/generic/tclGetDate.y
@@ -7,7 +7,7 @@
* only used when doing free-form date parsing, an ill-defined process
* anyway.
*
- * Copyright (c) 1992-1995 Karl Lehenbauer & Mark Diekhans.
+ * Copyright (c) 1992-1995 Karl Lehenbauer and Mark Diekhans.
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution of
@@ -16,7 +16,7 @@
%parse-param {DateInfo* info}
%lex-param {DateInfo* info}
-%define api.pure
+%pure-parser
/* %error-verbose would be nice, but our token names are meaningless */
%locations
@@ -27,7 +27,7 @@
* This file is generated from a yacc grammar defined in the file
* tclGetDate.y. It should not be edited directly.
*
- * Copyright (c) 1992-1995 Karl Lehenbauer & Mark Diekhans.
+ * Copyright (c) 1992-1995 Karl Lehenbauer and Mark Diekhans.
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution of
@@ -46,14 +46,6 @@
#endif /* _MSC_VER */
/*
- * Meridian: am, pm, or 24-hour style.
- */
-
-typedef enum _MERIDIAN {
- MERam, MERpm, MER24
-} MERIDIAN;
-
-/*
* yyparse will accept a 'struct DateInfo' as its parameter; that's where the
* parsed fields will be returned.
*/
@@ -71,7 +63,7 @@ typedef struct DateInfo {
time_t dateHour;
time_t dateMinutes;
time_t dateSeconds;
- MERIDIAN dateMeridian;
+ int dateMeridian;
int dateHaveTime;
time_t dateTimezone;
@@ -136,9 +128,9 @@ typedef struct DateInfo {
#define TM_YEAR_BASE 1900
-#define HOUR(x) ((int) (60 * (x)))
+#define HOUR(x) ((int) (60 * x))
#define SECSPERDAY (24L * 60L * 60L)
-#define IsLeapYear(x) (((x) % 4 == 0) && ((x) % 100 != 0 || (x) % 400 == 0))
+#define IsLeapYear(x) ((x % 4 == 0) && (x % 100 != 0 || x % 400 == 0))
/*
* An entry in the lexical lookup table.
@@ -158,6 +150,14 @@ typedef enum _DSTMODE {
DSTon, DSToff, DSTmaybe
} DSTMODE;
+/*
+ * Meridian: am, pm, or 24-hour style.
+ */
+
+typedef enum _MERIDIAN {
+ MERam, MERpm, MER24
+} MERIDIAN;
+
%}
%union {
@@ -266,32 +266,43 @@ time : tUNUMBER tMERIDIAN {
yySeconds = 0;
yyMeridian = $4;
}
+ | tUNUMBER ':' tUNUMBER '-' tUNUMBER {
+ yyHour = $1;
+ yyMinutes = $3;
+ yyMeridian = MER24;
+ yyDSTmode = DSToff;
+ yyTimezone = ($5 % 100 + ($5 / 100) * 60);
+ ++yyHaveZone;
+ }
| tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid {
yyHour = $1;
yyMinutes = $3;
yySeconds = $5;
yyMeridian = $6;
}
+ | tUNUMBER ':' tUNUMBER ':' tUNUMBER '-' tUNUMBER {
+ yyHour = $1;
+ yyMinutes = $3;
+ yySeconds = $5;
+ yyMeridian = MER24;
+ yyDSTmode = DSToff;
+ yyTimezone = ($7 % 100 + ($7 / 100) * 60);
+ ++yyHaveZone;
+ }
;
zone : tZONE tDST {
yyTimezone = $1;
- if (yyTimezone > HOUR( 12)) yyTimezone -= HOUR(100);
yyDSTmode = DSTon;
}
| tZONE {
yyTimezone = $1;
- if (yyTimezone > HOUR( 12)) yyTimezone -= HOUR(100);
yyDSTmode = DSToff;
}
| tDAYZONE {
yyTimezone = $1;
yyDSTmode = DSTon;
}
- | sign tUNUMBER {
- yyTimezone = -$1*($2 % 100 + ($2 / 100) * 60);
- yyDSTmode = DSToff;
- }
;
day : tDAY {
@@ -375,18 +386,8 @@ ordMonth: tNEXT tMONTH {
}
;
-iso : tUNUMBER '-' tUNUMBER '-' tUNUMBER tZONE
- tUNUMBER ':' tUNUMBER ':' tUNUMBER {
- if ($6 != HOUR( 7) + HOUR(100)) YYABORT;
- yyYear = $1;
- yyMonth = $3;
- yyDay = $5;
- yyHour = $7;
- yyMinutes = $9;
- yySeconds = $11;
- }
- | tISOBASE tZONE tISOBASE {
- if ($2 != HOUR( 7) + HOUR(100)) YYABORT;
+iso : tISOBASE tZONE tISOBASE {
+ if ($2 != HOUR( 7)) YYABORT;
yyYear = $1 / 10000;
yyMonth = ($1 % 10000)/100;
yyDay = $1 % 100;
@@ -395,7 +396,7 @@ iso : tUNUMBER '-' tUNUMBER '-' tUNUMBER tZONE
yySeconds = $3 % 100;
}
| tISOBASE tZONE tUNUMBER ':' tUNUMBER ':' tUNUMBER {
- if ($2 != HOUR( 7) + HOUR(100)) YYABORT;
+ if ($2 != HOUR( 7)) YYABORT;
yyYear = $1 / 10000;
yyMonth = ($1 % 10000)/100;
yyDay = $1 % 100;
@@ -501,6 +502,10 @@ o_merid : /* NULL */ {
;
%%
+MODULE_SCOPE int yychar;
+MODULE_SCOPE YYSTYPE yylval;
+MODULE_SCOPE int yynerrs;
+
/*
* Month and day table.
*/
@@ -530,7 +535,7 @@ static const TABLE MonthDayTable[] = {
{ "thurs", tDAY, 4 },
{ "friday", tDAY, 5 },
{ "saturday", tDAY, 6 },
- { NULL, 0, 0 }
+ { NULL }
};
/*
@@ -548,7 +553,7 @@ static const TABLE UnitsTable[] = {
{ "min", tSEC_UNIT, 60 },
{ "second", tSEC_UNIT, 1 },
{ "sec", tSEC_UNIT, 1 },
- { NULL, 0, 0 }
+ { NULL }
};
/*
@@ -580,7 +585,7 @@ static const TABLE OtherTable[] = {
{ "ago", tAGO, 1 },
{ "epoch", tEPOCH, 0 },
{ "stardate", tSTARDATE, 0 },
- { NULL, 0, 0 }
+ { NULL }
};
/*
@@ -618,8 +623,6 @@ static const TABLE TimezoneTable[] = {
{ "pdt", tDAYZONE, HOUR( 8) }, /* Pacific Daylight */
{ "yst", tZONE, HOUR( 9) }, /* Yukon Standard */
{ "ydt", tDAYZONE, HOUR( 9) }, /* Yukon Daylight */
- { "akst", tZONE, HOUR( 9) }, /* Alaska Standard */
- { "akdt", tDAYZONE, HOUR( 9) }, /* Alaska Daylight */
{ "hst", tZONE, HOUR(10) }, /* Hawaii Standard */
{ "hdt", tDAYZONE, HOUR(10) }, /* Hawaii Daylight */
{ "cat", tZONE, HOUR(10) }, /* Central Alaska */
@@ -643,7 +646,7 @@ static const TABLE TimezoneTable[] = {
{ "ist", tZONE, -HOUR(11/2) }, /* Indian Standard */
{ "zp6", tZONE, -HOUR( 6) }, /* USSR Zone 5 */
#if 0
- /* For completeness. NST is also Newfoundland Standard, and SST is
+ /* For completeness. NST is also Newfoundland Stanard, nad SST is
* also Swedish Summer. */
{ "nst", tZONE, -HOUR(13/2) }, /* North Sumatra */
{ "sst", tZONE, -HOUR( 7) }, /* South Sumatra, USSR Zone 6 */
@@ -668,7 +671,7 @@ static const TABLE TimezoneTable[] = {
/* ADDED BY Marco Nijdam */
{ "dst", tDST, HOUR( 0) }, /* DST on (hour is ignored) */
/* End ADDED */
- { NULL, 0, 0 }
+ { NULL }
};
/*
@@ -676,32 +679,32 @@ static const TABLE TimezoneTable[] = {
*/
static const TABLE MilitaryTable[] = {
- { "a", tZONE, -HOUR( 1) + HOUR(100) },
- { "b", tZONE, -HOUR( 2) + HOUR(100) },
- { "c", tZONE, -HOUR( 3) + HOUR(100) },
- { "d", tZONE, -HOUR( 4) + HOUR(100) },
- { "e", tZONE, -HOUR( 5) + HOUR(100) },
- { "f", tZONE, -HOUR( 6) + HOUR(100) },
- { "g", tZONE, -HOUR( 7) + HOUR(100) },
- { "h", tZONE, -HOUR( 8) + HOUR(100) },
- { "i", tZONE, -HOUR( 9) + HOUR(100) },
- { "k", tZONE, -HOUR(10) + HOUR(100) },
- { "l", tZONE, -HOUR(11) + HOUR(100) },
- { "m", tZONE, -HOUR(12) + HOUR(100) },
- { "n", tZONE, HOUR( 1) + HOUR(100) },
- { "o", tZONE, HOUR( 2) + HOUR(100) },
- { "p", tZONE, HOUR( 3) + HOUR(100) },
- { "q", tZONE, HOUR( 4) + HOUR(100) },
- { "r", tZONE, HOUR( 5) + HOUR(100) },
- { "s", tZONE, HOUR( 6) + HOUR(100) },
- { "t", tZONE, HOUR( 7) + HOUR(100) },
- { "u", tZONE, HOUR( 8) + HOUR(100) },
- { "v", tZONE, HOUR( 9) + HOUR(100) },
- { "w", tZONE, HOUR( 10) + HOUR(100) },
- { "x", tZONE, HOUR( 11) + HOUR(100) },
- { "y", tZONE, HOUR( 12) + HOUR(100) },
- { "z", tZONE, HOUR( 0) + HOUR(100) },
- { NULL, 0, 0 }
+ { "a", tZONE, -HOUR( 1) },
+ { "b", tZONE, -HOUR( 2) },
+ { "c", tZONE, -HOUR( 3) },
+ { "d", tZONE, -HOUR( 4) },
+ { "e", tZONE, -HOUR( 5) },
+ { "f", tZONE, -HOUR( 6) },
+ { "g", tZONE, -HOUR( 7) },
+ { "h", tZONE, -HOUR( 8) },
+ { "i", tZONE, -HOUR( 9) },
+ { "k", tZONE, -HOUR(10) },
+ { "l", tZONE, -HOUR(11) },
+ { "m", tZONE, -HOUR(12) },
+ { "n", tZONE, HOUR( 1) },
+ { "o", tZONE, HOUR( 2) },
+ { "p", tZONE, HOUR( 3) },
+ { "q", tZONE, HOUR( 4) },
+ { "r", tZONE, HOUR( 5) },
+ { "s", tZONE, HOUR( 6) },
+ { "t", tZONE, HOUR( 7) },
+ { "u", tZONE, HOUR( 8) },
+ { "v", tZONE, HOUR( 9) },
+ { "w", tZONE, HOUR( 10) },
+ { "x", tZONE, HOUR( 11) },
+ { "y", tZONE, HOUR( 12) },
+ { "z", tZONE, HOUR( 0) },
+ { NULL }
};
/*
@@ -718,12 +721,12 @@ TclDateerror(
Tcl_AppendToObj(infoPtr->messages, infoPtr->separatrix, -1);
Tcl_AppendToObj(infoPtr->messages, s, -1);
Tcl_AppendToObj(infoPtr->messages, " (characters ", -1);
- TclNewIntObj(t, location->first_column);
+ t = Tcl_NewIntObj(location->first_column);
Tcl_IncrRefCount(t);
Tcl_AppendObjToObj(infoPtr->messages, t);
Tcl_DecrRefCount(t);
Tcl_AppendToObj(infoPtr->messages, "-", -1);
- TclNewIntObj(t, location->last_column);
+ t = Tcl_NewIntObj(location->last_column);
Tcl_IncrRefCount(t);
Tcl_AppendObjToObj(infoPtr->messages, t);
Tcl_DecrRefCount(t);
@@ -766,9 +769,9 @@ LookupWord(
YYSTYPE* yylvalPtr,
char *buff)
{
- char *p;
- char *q;
- const TABLE *tp;
+ register char *p;
+ register char *q;
+ register const TABLE *tp;
int i, abbrev;
/*
@@ -891,14 +894,14 @@ TclDatelex(
YYLTYPE* location,
DateInfo *info)
{
- char c;
- char *p;
+ register char c;
+ register char *p;
char buff[20];
int Count;
location->first_column = yyInput - info->dateStart;
for ( ; ; ) {
- while (TclIsSpaceProcM(*yyInput)) {
+ while (isspace(UCHAR(*yyInput))) {
yyInput++;
}
@@ -961,10 +964,10 @@ TclDatelex(
int
TclClockOldscanObjCmd(
- TCL_UNUSED(void *),
+ ClientData clientData, /* Unused */
Tcl_Interp *interp, /* Tcl interpreter */
- int objc, /* Count of parameters */
- Tcl_Obj *const *objv) /* Parameters */
+ int objc, /* Count of paraneters */
+ Tcl_Obj *CONST *objv) /* Parameters */
{
Tcl_Obj *result, *resultElement;
int yr, mo, da;
@@ -978,7 +981,7 @@ TclClockOldscanObjCmd(
return TCL_ERROR;
}
- yyInput = TclGetString( objv[1] );
+ yyInput = Tcl_GetString( objv[1] );
dateInfo.dateStart = yyInput;
yyHaveDate = 0;
@@ -1004,7 +1007,7 @@ TclClockOldscanObjCmd(
yyHaveRel = 0;
yyRelMonth = 0; yyRelDay = 0; yyRelSeconds = 0; yyRelPointer = NULL;
- TclNewObj(dateInfo.messages);
+ dateInfo.messages = Tcl_NewObj();
dateInfo.separatrix = "";
Tcl_IncrRefCount(dateInfo.messages);
@@ -1012,12 +1015,10 @@ TclClockOldscanObjCmd(
if (status == 1) {
Tcl_SetObjResult(interp, dateInfo.messages);
Tcl_DecrRefCount(dateInfo.messages);
- Tcl_SetErrorCode(interp, "TCL", "VALUE", "DATE", "PARSE", (char *)NULL);
return TCL_ERROR;
} else if (status == 2) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("memory exhausted", -1));
Tcl_DecrRefCount(dateInfo.messages);
- Tcl_SetErrorCode(interp, "TCL", "MEMORY", (char *)NULL);
return TCL_ERROR;
} else if (status != 0) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("Unknown status returned "
@@ -1025,7 +1026,6 @@ TclClockOldscanObjCmd(
"report this error as a "
"bug in Tcl.", -1));
Tcl_DecrRefCount(dateInfo.messages);
- Tcl_SetErrorCode(interp, "TCL", "BUG", (char *)NULL);
return TCL_ERROR;
}
Tcl_DecrRefCount(dateInfo.messages);
@@ -1033,36 +1033,31 @@ TclClockOldscanObjCmd(
if (yyHaveDate > 1) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj("more than one date in string", -1));
- Tcl_SetErrorCode(interp, "TCL", "VALUE", "DATE", "MULTIPLE", (char *)NULL);
return TCL_ERROR;
}
if (yyHaveTime > 1) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj("more than one time of day in string", -1));
- Tcl_SetErrorCode(interp, "TCL", "VALUE", "DATE", "MULTIPLE", (char *)NULL);
return TCL_ERROR;
}
if (yyHaveZone > 1) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj("more than one time zone in string", -1));
- Tcl_SetErrorCode(interp, "TCL", "VALUE", "DATE", "MULTIPLE", (char *)NULL);
return TCL_ERROR;
}
if (yyHaveDay > 1) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj("more than one weekday in string", -1));
- Tcl_SetErrorCode(interp, "TCL", "VALUE", "DATE", "MULTIPLE", (char *)NULL);
return TCL_ERROR;
}
if (yyHaveOrdinalMonth > 1) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj("more than one ordinal month in string", -1));
- Tcl_SetErrorCode(interp, "TCL", "VALUE", "DATE", "MULTIPLE", (char *)NULL);
return TCL_ERROR;
}
- TclNewObj(result);
- TclNewObj(resultElement);
+ result = Tcl_NewObj();
+ resultElement = Tcl_NewObj();
if (yyHaveDate) {
Tcl_ListObjAppendElement(interp, resultElement,
Tcl_NewIntObj((int) yyYear));
@@ -1075,13 +1070,12 @@ TclClockOldscanObjCmd(
if (yyHaveTime) {
Tcl_ListObjAppendElement(interp, result, Tcl_NewIntObj((int)
- ToSeconds(yyHour, yyMinutes, yySeconds, (MERIDIAN)yyMeridian)));
+ ToSeconds(yyHour, yyMinutes, yySeconds, yyMeridian)));
} else {
- TclNewObj(resultElement);
- Tcl_ListObjAppendElement(interp, result, resultElement);
+ Tcl_ListObjAppendElement(interp, result, Tcl_NewObj());
}
- TclNewObj(resultElement);
+ resultElement = Tcl_NewObj();
if (yyHaveZone) {
Tcl_ListObjAppendElement(interp, resultElement,
Tcl_NewIntObj((int) -yyTimezone));
@@ -1090,7 +1084,7 @@ TclClockOldscanObjCmd(
}
Tcl_ListObjAppendElement(interp, result, resultElement);
- TclNewObj(resultElement);
+ resultElement = Tcl_NewObj();
if (yyHaveRel) {
Tcl_ListObjAppendElement(interp, resultElement,
Tcl_NewIntObj((int) yyRelMonth));
@@ -1101,7 +1095,7 @@ TclClockOldscanObjCmd(
}
Tcl_ListObjAppendElement(interp, result, resultElement);
- TclNewObj(resultElement);
+ resultElement = Tcl_NewObj();
if (yyHaveDay && !yyHaveDate) {
Tcl_ListObjAppendElement(interp, resultElement,
Tcl_NewIntObj((int) yyDayOrdinal));
@@ -1110,7 +1104,7 @@ TclClockOldscanObjCmd(
}
Tcl_ListObjAppendElement(interp, result, resultElement);
- TclNewObj(resultElement);
+ resultElement = Tcl_NewObj();
if (yyHaveOrdinalMonth) {
Tcl_ListObjAppendElement(interp, resultElement,
Tcl_NewIntObj((int) yyMonthOrdinal));