diff options
author | Kevin B Kenny <kennykb@acm.org> | 2004-09-17 19:41:00 (GMT) |
---|---|---|
committer | Kevin B Kenny <kennykb@acm.org> | 2004-09-17 19:41:00 (GMT) |
commit | fc4d1c3bfa9a6e5870ff9cee0cf575bd625d5b68 (patch) | |
tree | 54762a2862c182afdde27a4393fe8bc772b8ef13 /generic/tclGetDate.y | |
parent | 78d20dd0fad930674c60b4acf7a680392c4e460a (diff) | |
download | tcl-fc4d1c3bfa9a6e5870ff9cee0cf575bd625d5b68.zip tcl-fc4d1c3bfa9a6e5870ff9cee0cf575bd625d5b68.tar.gz tcl-fc4d1c3bfa9a6e5870ff9cee0cf575bd625d5b68.tar.bz2 |
make tclGetDate.y use bison instead of yacc
Diffstat (limited to 'generic/tclGetDate.y')
-rw-r--r-- | generic/tclGetDate.y | 132 |
1 files changed, 29 insertions, 103 deletions
diff --git a/generic/tclGetDate.y b/generic/tclGetDate.y index 1a8ed83..3c41d9b 100644 --- a/generic/tclGetDate.y +++ b/generic/tclGetDate.y @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclGetDate.y,v 1.22 2004/03/18 18:51:12 rmax Exp $ + * RCS: @(#) $Id: tclGetDate.y,v 1.23 2004/09/17 19:41:07 kennykb Exp $ */ %{ @@ -30,8 +30,16 @@ * SCCSID */ +/* + * Bison generates several labels that happen to be unused. MS Visual + * C++ doesn't like that, and complains. Tell it to shut up. + */ + +#ifdef _MSC_VER +#pragma warning( disable : 4102 ) +#endif /* _MSC_VER */ + #include "tclInt.h" -#include "tclPort.h" #define EPOCH 1970 #define START_OF_TIME 1902 @@ -81,6 +89,7 @@ typedef enum _MERIDIAN { * yacc had the %union construct.) Maybe someday; right now we only use * the %union very rarely. */ + static char *yyInput; static DSTMODE yyDSTmode; static time_t yyDayOrdinal; @@ -108,7 +117,7 @@ static time_t *yyRelPointer; /* * Prototypes of internal functions. */ -static void yyerror _ANSI_ARGS_((char *s)); +static void TclDateerror _ANSI_ARGS_((char *s)); static time_t ToSeconds _ANSI_ARGS_((time_t Hours, time_t Minutes, time_t Seconds, MERIDIAN Meridian)); static int Convert _ANSI_ARGS_((time_t Month, time_t Day, time_t Year, @@ -124,91 +133,8 @@ static int RelativeMonth _ANSI_ARGS_((time_t Start, time_t RelMonth, static int RelativeDay _ANSI_ARGS_((time_t Start, time_t RelDay, time_t *TimePtr)); static int LookupWord _ANSI_ARGS_((char *buff)); -static int yylex _ANSI_ARGS_((void)); - -int -yyparse _ANSI_ARGS_((void)); - -/* - *---------------------------------------------------------------------- - * - * TclDateCleanup -- - * - * Clean up allocated memory on process exit. - * - * Results: - * None. - * - * Side effects: - * Frees the block of memory passed in as client data. - * - *---------------------------------------------------------------------- - */ +static int TclDatelex _ANSI_ARGS_((void)); -static void -TclDateCleanup( ClientData clientData ) -{ - ckfree( (char*) clientData ); -} - -/* - *---------------------------------------------------------------------- - * - * TclDateAlloc -- - * - * Special purpose allocator for the two YACC stacks. - * - * Results: - * Returns a pointer to a block of memory. - * - * Side effects: - * Allocates the requested number of bytes, and - * sets up to delete the allocated memory on process exit. - * - * The YACC system is set up to free memory in its stacks only by - * abandonment. This procedure sets up to free it explicitly on exit - * from Tcl, as when unloading. - * - *---------------------------------------------------------------------- - */ - -static char* -TclDateAlloc( size_t n ) -{ - char* pointer = ckalloc( n ); - Tcl_CreateExitHandler( TclDateCleanup, (ClientData) pointer ); - return pointer; -} - -/* - *---------------------------------------------------------------------- - * - * TclDateRealloc -- - * - * Special purpose allocator for the two YACC stacks. - * - * Results: - * Returns a pointer to a block of memory. - * - * Side effects: - * Allocates the requested number of bytes, and - * sets up to delete the allocated memory on process exit. - * - * The YACC system is set up to free memory in its stacks only by - * abandonment. This procedure sets up to free it explicitly on exit - * from Tcl, as when unloading. - * - *---------------------------------------------------------------------- - */ -static char* -TclDateRealloc( char* oldPointer, size_t n ) -{ - char* newPointer; - Tcl_DeleteExitHandler( TclDateCleanup, (ClientData) oldPointer ); - newPointer = ckrealloc( oldPointer, n ); - Tcl_CreateExitHandler( TclDateCleanup, (ClientData) newPointer ); - return newPointer; -} %} @@ -681,7 +607,7 @@ static TABLE MilitaryTable[] = { * Dump error messages in the bit bucket. */ static void -yyerror(s) +TclDateerror(s) char *s; { } @@ -785,7 +711,7 @@ Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode, TimePtr) /* Perform a preliminary DST compensation ?? */ if (DSTmode == DSTon - || (DSTmode == DSTmaybe && TclpGetDate(Julian, 0)->tm_isdst)) + || (DSTmode == DSTmaybe && TclpGetDate(&Julian, 0)->tm_isdst)) Julian -= 60 * 60; *TimePtr = Julian; return 0; @@ -799,8 +725,8 @@ DSTcorrect(Start, Future) { time_t StartDay; time_t FutureDay; - StartDay = (TclpGetDate(Start, 0)->tm_hour + 1) % 24; - FutureDay = (TclpGetDate(Future, 0)->tm_hour + 1) % 24; + StartDay = (TclpGetDate(&Start, 0)->tm_hour + 1) % 24; + FutureDay = (TclpGetDate(&Future, 0)->tm_hour + 1) % 24; return (Future - Start) + (StartDay - FutureDay) * 60L * 60L; } @@ -815,7 +741,7 @@ NamedDay(Start, DayOrdinal, DayNumber) time_t now; now = Start; - tm = TclpGetDate(now, 0); + tm = TclpGetDate(&now, 0); now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7); now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1); return DSTcorrect(Start, now); @@ -832,7 +758,7 @@ NamedMonth(Start, MonthOrdinal, MonthNumber) int result; now = Start; - tm = TclpGetDate(now, 0); + tm = TclpGetDate(&now, 0); /* To compute the next n'th month, we use this alg: * add n to year value * if currentMonth < requestedMonth decrement year value by 1 (so that @@ -867,7 +793,7 @@ RelativeMonth(Start, RelMonth, TimePtr) *TimePtr = 0; return 0; } - tm = TclpGetDate(Start, 0); + tm = TclpGetDate(&Start, 0); Month = 12 * (tm->tm_year + TM_YEAR_BASE) + tm->tm_mon + RelMonth; Year = Month / 12; Month = Month % 12 + 1; @@ -887,7 +813,7 @@ RelativeMonth(Start, RelMonth, TimePtr) * to timezone difference with GMT to Julian time, if GMT flag is true. */ - if (TclDateTimezone == 0) { + if (yyTimezone == 0) { Julian += TclpGetTimeZone((unsigned long) Start) * 60L; } @@ -1064,7 +990,7 @@ LookupWord(buff) static int -yylex() +TclDatelex() { register char c; register char *p; @@ -1140,7 +1066,7 @@ TclGetDate(p, now, zone, timePtr) yyInput = p; /* now has to be cast to a time_t for 64bit compliance */ Start = now; - tm = TclpGetDate(Start, (zone == -50000)); + tm = TclpGetDate(&Start, (zone == -50000)); thisyear = tm->tm_year + TM_YEAR_BASE; yyYear = thisyear; yyMonth = tm->tm_mon + 1; @@ -1174,8 +1100,8 @@ TclGetDate(p, now, zone, timePtr) } if (yyHaveDate || yyHaveTime || yyHaveDay) { - if (TclDateYear < 0) { - TclDateYear = -TclDateYear; + if (yyYear < 0) { + yyYear = -yyYear; } /* * The following line handles years that are specified using @@ -1187,11 +1113,11 @@ TclGetDate(p, now, zone, timePtr) * This later definition should work on all platforms. */ - if (TclDateYear < 100) { - if (TclDateYear >= 69) { - TclDateYear += 1900; + if (yyYear < 100) { + if (yyYear >= 69) { + yyYear += 1900; } else { - TclDateYear += 2000; + yyYear += 2000; } } if (Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds, |