| 1 |
/* |
| 2 |
* tclGetDate.y -- |
| 3 |
* |
| 4 |
* Contains yacc grammar for parsing date and time strings. |
| 5 |
* The output of this file should be the file tclDate.c which |
| 6 |
* is used directly in the Tcl sources. |
| 7 |
* |
| 8 |
* Copyright (c) 1992-1995 Karl Lehenbauer and Mark Diekhans. |
| 9 |
* Copyright (c) 1995-1997 Sun Microsystems, Inc. |
| 10 |
* |
| 11 |
* See the file "license.terms" for information on usage and redistribution |
| 12 |
* of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 13 |
* |
| 14 |
* RCS: @(#) $Id: tclGetDate.y,v 1.18 2001/10/18 20:20:28 hobbs Exp $ |
| 15 |
*/ |
| 16 |
|
| 17 |
%{ |
| 18 |
/* |
| 19 |
* tclDate.c -- |
| 20 |
* |
| 21 |
* This file is generated from a yacc grammar defined in |
| 22 |
* the file tclGetDate.y. It should not be edited directly. |
| 23 |
* |
| 24 |
* Copyright (c) 1992-1995 Karl Lehenbauer and Mark Diekhans. |
| 25 |
* Copyright (c) 1995-1997 Sun Microsystems, Inc. |
| 26 |
* |
| 27 |
* See the file "license.terms" for information on usage and redistribution |
| 28 |
* of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 29 |
* |
| 30 |
* SCCSID |
| 31 |
*/ |
| 32 |
|
| 33 |
#include "tclInt.h" |
| 34 |
#include "tclPort.h" |
| 35 |
|
| 36 |
#if defined(MAC_TCL) && !defined(TCL_MAC_USE_MSL_EPOCH) |
| 37 |
# define EPOCH 1904 |
| 38 |
# define START_OF_TIME 1904 |
| 39 |
# define END_OF_TIME 2039 |
| 40 |
#else |
| 41 |
# define EPOCH 1970 |
| 42 |
# define START_OF_TIME 1902 |
| 43 |
# define END_OF_TIME 2037 |
| 44 |
#endif |
| 45 |
|
| 46 |
/* |
| 47 |
* The offset of tm_year of struct tm returned by localtime, gmtime, etc. |
| 48 |
* I don't know how universal this is; K&R II, the NetBSD manpages, and |
| 49 |
* ../compat/strftime.c all agree that tm_year is the year-1900. However, |
| 50 |
* some systems may have a different value. This #define should be the |
| 51 |
* same as in ../compat/strftime.c. |
| 52 |
*/ |
| 53 |
#define TM_YEAR_BASE 1900 |
| 54 |
|
| 55 |
#define HOUR(x) ((int) (60 * x)) |
| 56 |
#define SECSPERDAY (24L * 60L * 60L) |
| 57 |
#define IsLeapYear(x) ((x % 4 == 0) && (x % 100 != 0 || x % 400 == 0)) |
| 58 |
|
| 59 |
/* |
| 60 |
* An entry in the lexical lookup table. |
| 61 |
*/ |
| 62 |
typedef struct _TABLE { |
| 63 |
char *name; |
| 64 |
int type; |
| 65 |
time_t value; |
| 66 |
} TABLE; |
| 67 |
|
| 68 |
|
| 69 |
/* |
| 70 |
* Daylight-savings mode: on, off, or not yet known. |
| 71 |
*/ |
| 72 |
typedef enum _DSTMODE { |
| 73 |
DSTon, DSToff, DSTmaybe |
| 74 |
} DSTMODE; |
| 75 |
|
| 76 |
/* |
| 77 |
* Meridian: am, pm, or 24-hour style. |
| 78 |
*/ |
| 79 |
typedef enum _MERIDIAN { |
| 80 |
MERam, MERpm, MER24 |
| 81 |
} MERIDIAN; |
| 82 |
|
| 83 |
|
| 84 |
/* |
| 85 |
* Global variables. We could get rid of most of these by using a good |
| 86 |
* union as the yacc stack. (This routine was originally written before |
| 87 |
* yacc had the %union construct.) Maybe someday; right now we only use |
| 88 |
* the %union very rarely. |
| 89 |
*/ |
| 90 |
static char *yyInput; |
| 91 |
static DSTMODE yyDSTmode; |
| 92 |
static time_t yyDayOrdinal; |
| 93 |
static time_t yyDayNumber; |
| 94 |
static time_t yyMonthOrdinal; |
| 95 |
static int yyHaveDate; |
| 96 |
static int yyHaveDay; |
| 97 |
static int yyHaveOrdinalMonth; |
| 98 |
static int yyHaveRel; |
| 99 |
static int yyHaveTime; |
| 100 |
static int yyHaveZone; |
| 101 |
static time_t yyTimezone; |
| 102 |
static time_t yyDay; |
| 103 |
static time_t yyHour; |
| 104 |
static time_t yyMinutes; |
| 105 |
static time_t yyMonth; |
| 106 |
static time_t yySeconds; |
| 107 |
static time_t yyYear; |
| 108 |
static MERIDIAN yyMeridian; |
| 109 |
static time_t yyRelMonth; |
| 110 |
static time_t yyRelDay; |
| 111 |
static time_t yyRelSeconds; |
| 112 |
static time_t *yyRelPointer; |
| 113 |
|
| 114 |
/* |
| 115 |
* Prototypes of internal functions. |
| 116 |
*/ |
| 117 |
static void yyerror _ANSI_ARGS_((char *s)); |
| 118 |
static time_t ToSeconds _ANSI_ARGS_((time_t Hours, time_t Minutes, |
| 119 |
time_t Seconds, MERIDIAN Meridian)); |
| 120 |
static int Convert _ANSI_ARGS_((time_t Month, time_t Day, time_t Year, |
| 121 |
time_t Hours, time_t Minutes, time_t Seconds, |
| 122 |
MERIDIAN Meridia, DSTMODE DSTmode, time_t *TimePtr)); |
| 123 |
static time_t DSTcorrect _ANSI_ARGS_((time_t Start, time_t Future)); |
| 124 |
static time_t NamedDay _ANSI_ARGS_((time_t Start, time_t DayOrdinal, |
| 125 |
time_t DayNumber)); |
| 126 |
static time_t NamedMonth _ANSI_ARGS_((time_t Start, time_t MonthOrdinal, |
| 127 |
time_t MonthNumber)); |
| 128 |
static int RelativeMonth _ANSI_ARGS_((time_t Start, time_t RelMonth, |
| 129 |
time_t *TimePtr)); |
| 130 |
static int RelativeDay _ANSI_ARGS_((time_t Start, time_t RelDay, |
| 131 |
time_t *TimePtr)); |
| 132 |
static int LookupWord _ANSI_ARGS_((char *buff)); |
| 133 |
static int yylex _ANSI_ARGS_((void)); |
| 134 |
|
| 135 |
int |
| 136 |
yyparse _ANSI_ARGS_((void)); |
| 137 |
%} |
| 138 |
|
| 139 |
%union { |
| 140 |
time_t Number; |
| 141 |
enum _MERIDIAN Meridian; |
| 142 |
} |
| 143 |
|
| 144 |
%token tAGO tDAY tDAYZONE tID tMERIDIAN tMINUTE_UNIT tMONTH tMONTH_UNIT |
| 145 |
%token tSTARDATE tSEC_UNIT tSNUMBER tUNUMBER tZONE tEPOCH tDST tISOBASE |
| 146 |
%token tDAY_UNIT tNEXT |
| 147 |
|
| 148 |
%type <Number> tDAY tDAYZONE tMINUTE_UNIT tMONTH tMONTH_UNIT tDST |
| 149 |
%type <Number> tSEC_UNIT tSNUMBER tUNUMBER tZONE tISOBASE tDAY_UNIT |
| 150 |
%type <Number> unit sign tNEXT tSTARDATE |
| 151 |
%type <Meridian> tMERIDIAN o_merid |
| 152 |
|
| 153 |
%% |
| 154 |
|
| 155 |
spec : /* NULL */ |
| 156 |
| spec item |
| 157 |
; |
| 158 |
|
| 159 |
item : time { |
| 160 |
yyHaveTime++; |
| 161 |
} |
| 162 |
| zone { |
| 163 |
yyHaveZone++; |
| 164 |
} |
| 165 |
| date { |
| 166 |
yyHaveDate++; |
| 167 |
} |
| 168 |
| ordMonth { |
| 169 |
yyHaveOrdinalMonth++; |
| 170 |
} |
| 171 |
| day { |
| 172 |
yyHaveDay++; |
| 173 |
} |
| 174 |
| relspec { |
| 175 |
yyHaveRel++; |
| 176 |
} |
| 177 |
| iso { |
| 178 |
yyHaveTime++; |
| 179 |
yyHaveDate++; |
| 180 |
} |
| 181 |
| trek { |
| 182 |
yyHaveTime++; |
| 183 |
yyHaveDate++; |
| 184 |
yyHaveRel++; |
| 185 |
} |
| 186 |
| number |
| 187 |
; |
| 188 |
|
| 189 |
time : tUNUMBER tMERIDIAN { |
| 190 |
yyHour = $1; |
| 191 |
yyMinutes = 0; |
| 192 |
yySeconds = 0; |
| 193 |
yyMeridian = $2; |
| 194 |
} |
| 195 |
| tUNUMBER ':' tUNUMBER o_merid { |
| 196 |
yyHour = $1; |
| 197 |
yyMinutes = $3; |
| 198 |
yySeconds = 0; |
| 199 |
yyMeridian = $4; |
| 200 |
} |
| 201 |
| tUNUMBER ':' tUNUMBER '-' tUNUMBER { |
| 202 |
yyHour = $1; |
| 203 |
yyMinutes = $3; |
| 204 |
yyMeridian = MER24; |
| 205 |
yyDSTmode = DSToff; |
| 206 |
yyTimezone = ($5 % 100 + ($5 / 100) * 60); |
| 207 |
} |
| 208 |
| tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid { |
| 209 |
yyHour = $1; |
| 210 |
yyMinutes = $3; |
| 211 |
yySeconds = $5; |
| 212 |
yyMeridian = $6; |
| 213 |
} |
| 214 |
| tUNUMBER ':' tUNUMBER ':' tUNUMBER '-' tUNUMBER { |
| 215 |
yyHour = $1; |
| 216 |
yyMinutes = $3; |
| 217 |
yySeconds = $5; |
| 218 |
yyMeridian = MER24; |
| 219 |
yyDSTmode = DSToff; |
| 220 |
yyTimezone = ($7 % 100 + ($7 / 100) * 60); |
| 221 |
} |
| 222 |
; |
| 223 |
|
| 224 |
zone : tZONE tDST { |
| 225 |
yyTimezone = $1; |
| 226 |
yyDSTmode = DSTon; |
| 227 |
} |
| 228 |
| tZONE { |
| 229 |
yyTimezone = $1; |
| 230 |
yyDSTmode = DSToff; |
| 231 |
} |
| 232 |
| tDAYZONE { |
| 233 |
yyTimezone = $1; |
| 234 |
yyDSTmode = DSTon; |
| 235 |
} |
| 236 |
; |
| 237 |
|
| 238 |
day : tDAY { |
| 239 |
yyDayOrdinal = 1; |
| 240 |
yyDayNumber = $1; |
| 241 |
} |
| 242 |
| tDAY ',' { |
| 243 |
yyDayOrdinal = 1; |
| 244 |
yyDayNumber = $1; |
| 245 |
} |
| 246 |
| tUNUMBER tDAY { |
| 247 |
yyDayOrdinal = $1; |
| 248 |
yyDayNumber = $2; |
| 249 |
} |
| 250 |
| sign tUNUMBER tDAY { |
| 251 |
yyDayOrdinal = $1 * $2; |
| 252 |
yyDayNumber = $3; |
| 253 |
} |
| 254 |
| tNEXT tDAY { |
| 255 |
yyDayOrdinal = 2; |
| 256 |
yyDayNumber = $2; |
| 257 |
} |
| 258 |
; |
| 259 |
|
| 260 |
date : tUNUMBER '/' tUNUMBER { |
| 261 |
yyMonth = $1; |
| 262 |
yyDay = $3; |
| 263 |
} |
| 264 |
| tUNUMBER '/' tUNUMBER '/' tUNUMBER { |
| 265 |
yyMonth = $1; |
| 266 |
yyDay = $3; |
| 267 |
yyYear = $5; |
| 268 |
} |
| 269 |
| tISOBASE { |
| 270 |
yyYear = $1 / 10000; |
| 271 |
yyMonth = ($1 % 10000)/100; |
| 272 |
yyDay = $1 % 100; |
| 273 |
} |
| 274 |
| tUNUMBER '-' tMONTH '-' tUNUMBER { |
| 275 |
yyDay = $1; |
| 276 |
yyMonth = $3; |
| 277 |
yyYear = $5; |
| 278 |
} |
| 279 |
| tUNUMBER '-' tUNUMBER '-' tUNUMBER { |
| 280 |
yyMonth = $3; |
| 281 |
yyDay = $5; |
| 282 |
yyYear = $1; |
| 283 |
} |
| 284 |
| tMONTH tUNUMBER { |
| 285 |
yyMonth = $1; |
| 286 |
yyDay = $2; |
| 287 |
} |
| 288 |
| tMONTH tUNUMBER ',' tUNUMBER { |
| 289 |
yyMonth = $1; |
| 290 |
yyDay = $2; |
| 291 |
yyYear = $4; |
| 292 |
} |
| 293 |
| tUNUMBER tMONTH { |
| 294 |
yyMonth = $2; |
| 295 |
yyDay = $1; |
| 296 |
} |
| 297 |
| tEPOCH { |
| 298 |
yyMonth = 1; |
| 299 |
yyDay = 1; |
| 300 |
yyYear = EPOCH; |
| 301 |
} |
| 302 |
| tUNUMBER tMONTH tUNUMBER { |
| 303 |
yyMonth = $2; |
| 304 |
yyDay = $1; |
| 305 |
yyYear = $3; |
| 306 |
} |
| 307 |
; |
| 308 |
|
| 309 |
ordMonth: tNEXT tMONTH { |
| 310 |
yyMonthOrdinal = 1; |
| 311 |
yyMonth = $2; |
| 312 |
} |
| 313 |
| tNEXT tUNUMBER tMONTH { |
| 314 |
yyMonthOrdinal = $2; |
| 315 |
yyMonth = $3; |
| 316 |
} |
| 317 |
; |
| 318 |
|
| 319 |
iso : tISOBASE tZONE tISOBASE { |
| 320 |
if ($2 != HOUR(- 7)) YYABORT; |
| 321 |
yyYear = $1 / 10000; |
| 322 |
yyMonth = ($1 % 10000)/100; |
| 323 |
yyDay = $1 % 100; |
| 324 |
yyHour = $3 / 10000; |
| 325 |
yyMinutes = ($3 % 10000)/100; |
| 326 |
yySeconds = $3 % 100; |
| 327 |
} |
| 328 |
| tISOBASE tZONE tUNUMBER ':' tUNUMBER ':' tUNUMBER { |
| 329 |
if ($2 != HOUR(- 7)) YYABORT; |
| 330 |
yyYear = $1 / 10000; |
| 331 |
yyMonth = ($1 % 10000)/100; |
| 332 |
yyDay = $1 % 100; |
| 333 |
yyHour = $3; |
| 334 |
yyMinutes = $5; |
| 335 |
yySeconds = $7; |
| 336 |
} |
| 337 |
| tISOBASE tISOBASE { |
| 338 |
yyYear = $1 / 10000; |
| 339 |
yyMonth = ($1 % 10000)/100; |
| 340 |
yyDay = $1 % 100; |
| 341 |
yyHour = $2 / 10000; |
| 342 |
yyMinutes = ($2 % 10000)/100; |
| 343 |
yySeconds = $2 % 100; |
| 344 |
} |
| 345 |
; |
| 346 |
|
| 347 |
trek : tSTARDATE tUNUMBER '.' tUNUMBER { |
| 348 |
/* |
| 349 |
* Offset computed year by -377 so that the returned years will |
| 350 |
* be in a range accessible with a 32 bit clock seconds value |
| 351 |
*/ |
| 352 |
yyYear = $2/1000 + 2323 - 377; |
| 353 |
yyDay = 1; |
| 354 |
yyMonth = 1; |
| 355 |
yyRelDay += (($2%1000)*(365 + IsLeapYear(yyYear)))/1000; |
| 356 |
yyRelSeconds += $4 * 144 * 60; |
| 357 |
} |
| 358 |
; |
| 359 |
|
| 360 |
relspec : relunits tAGO { |
| 361 |
yyRelSeconds *= -1; |
| 362 |
yyRelMonth *= -1; |
| 363 |
yyRelDay *= -1; |
| 364 |
} |
| 365 |
| relunits |
| 366 |
; |
| 367 |
relunits : sign tUNUMBER unit { *yyRelPointer += $1 * $2 * $3; } |
| 368 |
| tUNUMBER unit { *yyRelPointer += $1 * $2; } |
| 369 |
| tNEXT unit { *yyRelPointer += $2; } |
| 370 |
| tNEXT tUNUMBER unit { *yyRelPointer += $2 * $3; } |
| 371 |
| unit { *yyRelPointer += $1; } |
| 372 |
; |
| 373 |
sign : '-' { $$ = -1; } |
| 374 |
| '+' { $$ = 1; } |
| 375 |
; |
| 376 |
unit : tSEC_UNIT { $$ = $1; yyRelPointer = &yyRelSeconds; } |
| 377 |
| tDAY_UNIT { $$ = $1; yyRelPointer = &yyRelDay; } |
| 378 |
| tMONTH_UNIT { $$ = $1; yyRelPointer = &yyRelMonth; } |
| 379 |
; |
| 380 |
|
| 381 |
number : tUNUMBER |
| 382 |
{ |
| 383 |
if (yyHaveTime && yyHaveDate && !yyHaveRel) { |
| 384 |
yyYear = $1; |
| 385 |
} else { |
| 386 |
yyHaveTime++; |
| 387 |
if ($1 < 100) { |
| 388 |
yyHour = $1; |
| 389 |
yyMinutes = 0; |
| 390 |
} else { |
| 391 |
yyHour = $1 / 100; |
| 392 |
yyMinutes = $1 % 100; |
| 393 |
} |
| 394 |
yySeconds = 0; |
| 395 |
yyMeridian = MER24; |
| 396 |
} |
| 397 |
} |
| 398 |
; |
| 399 |
|
| 400 |
o_merid : /* NULL */ { |
| 401 |
$$ = MER24; |
| 402 |
} |
| 403 |
| tMERIDIAN { |
| 404 |
$$ = $1; |
| 405 |
} |
| 406 |
; |
| 407 |
|
| 408 |
%% |
| 409 |
|
| 410 |
/* |
| 411 |
* Month and day table. |
| 412 |
*/ |
| 413 |
static TABLE MonthDayTable[] = { |
| 414 |
{ "january", tMONTH, 1 }, |
| 415 |
{ "february", tMONTH, 2 }, |
| 416 |
{ "march", tMONTH, 3 }, |
| 417 |
{ "april", tMONTH, 4 }, |
| 418 |
{ "may", tMONTH, 5 }, |
| 419 |
{ "june", tMONTH, 6 }, |
| 420 |
{ "july", tMONTH, 7 }, |
| 421 |
{ "august", tMONTH, 8 }, |
| 422 |
{ "september", tMONTH, 9 }, |
| 423 |
{ "sept", tMONTH, 9 }, |
| 424 |
{ "october", tMONTH, 10 }, |
| 425 |
{ "november", tMONTH, 11 }, |
| 426 |
{ "december", tMONTH, 12 }, |
| 427 |
{ "sunday", tDAY, 0 }, |
| 428 |
{ "monday", tDAY, 1 }, |
| 429 |
{ "tuesday", tDAY, 2 }, |
| 430 |
{ "tues", tDAY, 2 }, |
| 431 |
{ "wednesday", tDAY, 3 }, |
| 432 |
{ "wednes", tDAY, 3 }, |
| 433 |
{ "thursday", tDAY, 4 }, |
| 434 |
{ "thur", tDAY, 4 }, |
| 435 |
{ "thurs", tDAY, 4 }, |
| 436 |
{ "friday", tDAY, 5 }, |
| 437 |
{ "saturday", tDAY, 6 }, |
| 438 |
{ NULL } |
| 439 |
}; |
| 440 |
|
| 441 |
/* |
| 442 |
* Time units table. |
| 443 |
*/ |
| 444 |
static TABLE UnitsTable[] = { |
| 445 |
{ "year", tMONTH_UNIT, 12 }, |
| 446 |
{ "month", tMONTH_UNIT, 1 }, |
| 447 |
{ "fortnight", tDAY_UNIT, 14 }, |
| 448 |
{ "week", tDAY_UNIT, 7 }, |
| 449 |
{ "day", tDAY_UNIT, 1 }, |
| 450 |
{ "hour", tSEC_UNIT, 60 * 60 }, |
| 451 |
{ "minute", tSEC_UNIT, 60 }, |
| 452 |
{ "min", tSEC_UNIT, 60 }, |
| 453 |
{ "second", tSEC_UNIT, 1 }, |
| 454 |
{ "sec", tSEC_UNIT, 1 }, |
| 455 |
{ NULL } |
| 456 |
}; |
| 457 |
|
| 458 |
/* |
| 459 |
* Assorted relative-time words. |
| 460 |
*/ |
| 461 |
static TABLE OtherTable[] = { |
| 462 |
{ "tomorrow", tDAY_UNIT, 1 }, |
| 463 |
{ "yesterday", tDAY_UNIT, -1 }, |
| 464 |
{ "today", tDAY_UNIT, 0 }, |
| 465 |
{ "now", tSEC_UNIT, 0 }, |
| 466 |
{ "last", tUNUMBER, -1 }, |
| 467 |
{ "this", tSEC_UNIT, 0 }, |
| 468 |
{ "next", tNEXT, 1 }, |
| 469 |
#if 0 |
| 470 |
{ "first", tUNUMBER, 1 }, |
| 471 |
{ "second", tUNUMBER, 2 }, |
| 472 |
{ "third", tUNUMBER, 3 }, |
| 473 |
{ "fourth", tUNUMBER, 4 }, |
| 474 |
{ "fifth", tUNUMBER, 5 }, |
| 475 |
{ "sixth", tUNUMBER, 6 }, |
| 476 |
{ "seventh", tUNUMBER, 7 }, |
| 477 |
{ "eighth", tUNUMBER, 8 }, |
| 478 |
{ "ninth", tUNUMBER, 9 }, |
| 479 |
{ "tenth", tUNUMBER, 10 }, |
| 480 |
{ "eleventh", tUNUMBER, 11 }, |
| 481 |
{ "twelfth", tUNUMBER, 12 }, |
| 482 |
#endif |
| 483 |
{ "ago", tAGO, 1 }, |
| 484 |
{ "epoch", tEPOCH, 0 }, |
| 485 |
{ "stardate", tSTARDATE, 0}, |
| 486 |
{ NULL } |
| 487 |
}; |
| 488 |
|
| 489 |
/* |
| 490 |
* The timezone table. (Note: This table was modified to not use any floating |
| 491 |
* point constants to work around an SGI compiler bug). |
| 492 |
*/ |
| 493 |
static TABLE TimezoneTable[] = { |
| 494 |
{ "gmt", tZONE, HOUR( 0) }, /* Greenwich Mean */ |
| 495 |
{ "ut", tZONE, HOUR( 0) }, /* Universal (Coordinated) */ |
| 496 |
{ "utc", tZONE, HOUR( 0) }, |
| 497 |
{ "uct", tZONE, HOUR( 0) }, /* Universal Coordinated Time */ |
| 498 |
{ "wet", tZONE, HOUR( 0) }, /* Western European */ |
| 499 |
{ "bst", tDAYZONE, HOUR( 0) }, /* British Summer */ |
| 500 |
{ "wat", tZONE, HOUR( 1) }, /* West Africa */ |
| 501 |
{ "at", tZONE, HOUR( 2) }, /* Azores */ |
| 502 |
#if 0 |
| 503 |
/* For completeness. BST is also British Summer, and GST is |
| 504 |
* also Guam Standard. */ |
| 505 |
{ "bst", tZONE, HOUR( 3) }, /* Brazil Standard */ |
| 506 |
{ "gst", tZONE, HOUR( 3) }, /* Greenland Standard */ |
| 507 |
#endif |
| 508 |
{ "nft", tZONE, HOUR( 7/2) }, /* Newfoundland */ |
| 509 |
{ "nst", tZONE, HOUR( 7/2) }, /* Newfoundland Standard */ |
| 510 |
{ "ndt", tDAYZONE, HOUR( 7/2) }, /* Newfoundland Daylight */ |
| 511 |
{ "ast", tZONE, HOUR( 4) }, /* Atlantic Standard */ |
| 512 |
{ "adt", tDAYZONE, HOUR( 4) }, /* Atlantic Daylight */ |
| 513 |
{ "est", tZONE, HOUR( 5) }, /* Eastern Standard */ |
| 514 |
{ "edt", tDAYZONE, HOUR( 5) }, /* Eastern Daylight */ |
| 515 |
{ "cst", tZONE, HOUR( 6) }, /* Central Standard */ |
| 516 |
{ "cdt", tDAYZONE, HOUR( 6) }, /* Central Daylight */ |
| 517 |
{ "mst", tZONE, HOUR( 7) }, /* Mountain Standard */ |
| 518 |
{ "mdt", tDAYZONE, HOUR( 7) }, /* Mountain Daylight */ |
| 519 |
{ "pst", tZONE, HOUR( 8) }, /* Pacific Standard */ |
| 520 |
{ "pdt", tDAYZONE, HOUR( 8) }, /* Pacific Daylight */ |
| 521 |
{ "yst", tZONE, HOUR( 9) }, /* Yukon Standard */ |
| 522 |
{ "ydt", tDAYZONE, HOUR( 9) }, /* Yukon Daylight */ |
| 523 |
{ "hst", tZONE, HOUR(10) }, /* Hawaii Standard */ |
| 524 |
{ "hdt", tDAYZONE, HOUR(10) }, /* Hawaii Daylight */ |
| 525 |
{ "cat", tZONE, HOUR(10) }, /* Central Alaska */ |
| 526 |
{ "ahst", tZONE, HOUR(10) }, /* Alaska-Hawaii Standard */ |
| 527 |
{ "nt", tZONE, HOUR(11) }, /* Nome */ |
| 528 |
{ "idlw", tZONE, HOUR(12) }, /* International Date Line West */ |
| 529 |
{ "cet", tZONE, -HOUR( 1) }, /* Central European */ |
| 530 |
{ "cest", tDAYZONE, -HOUR( 1) }, /* Central European Summer */ |
| 531 |
{ "met", tZONE, -HOUR( 1) }, /* Middle European */ |
| 532 |
{ "mewt", tZONE, -HOUR( 1) }, /* Middle European Winter */ |
| 533 |
{ "mest", tDAYZONE, -HOUR( 1) }, /* Middle European Summer */ |
| 534 |
{ "swt", tZONE, -HOUR( 1) }, /* Swedish Winter */ |
| 535 |
{ "sst", tDAYZONE, -HOUR( 1) }, /* Swedish Summer */ |
| 536 |
{ "fwt", tZONE, -HOUR( 1) }, /* French Winter */ |
| 537 |
{ "fst", tDAYZONE, -HOUR( 1) }, /* French Summer */ |
| 538 |
{ "eet", tZONE, -HOUR( 2) }, /* Eastern Europe, USSR Zone 1 */ |
| 539 |
{ "bt", tZONE, -HOUR( 3) }, /* Baghdad, USSR Zone 2 */ |
| 540 |
{ "it", tZONE, -HOUR( 7/2) }, /* Iran */ |
| 541 |
{ "zp4", tZONE, -HOUR( 4) }, /* USSR Zone 3 */ |
| 542 |
{ "zp5", tZONE, -HOUR( 5) }, /* USSR Zone 4 */ |
| 543 |
{ "ist", tZONE, -HOUR(11/2) }, /* Indian Standard */ |
| 544 |
{ "zp6", tZONE, -HOUR( 6) }, /* USSR Zone 5 */ |
| 545 |
#if 0 |
| 546 |
/* For completeness. NST is also Newfoundland Stanard, nad SST is |
| 547 |
* also Swedish Summer. */ |
| 548 |
{ "nst", tZONE, -HOUR(13/2) }, /* North Sumatra */ |
| 549 |
{ "sst", tZONE, -HOUR( 7) }, /* South Sumatra, USSR Zone 6 */ |
| 550 |
#endif /* 0 */ |
| 551 |
{ "wast", tZONE, -HOUR( 7) }, /* West Australian Standard */ |
| 552 |
{ "wadt", tDAYZONE, -HOUR( 7) }, /* West Australian Daylight */ |
| 553 |
{ "jt", tZONE, -HOUR(15/2) }, /* Java (3pm in Cronusland!) */ |
| 554 |
{ "cct", tZONE, -HOUR( 8) }, /* China Coast, USSR Zone 7 */ |
| 555 |
{ "jst", tZONE, -HOUR( 9) }, /* Japan Standard, USSR Zone 8 */ |
| 556 |
{ "cast", tZONE, -HOUR(19/2) }, /* Central Australian Standard */ |
| 557 |
{ "cadt", tDAYZONE, -HOUR(19/2) }, /* Central Australian Daylight */ |
| 558 |
{ "east", tZONE, -HOUR(10) }, /* Eastern Australian Standard */ |
| 559 |
{ "eadt", tDAYZONE, -HOUR(10) }, /* Eastern Australian Daylight */ |
| 560 |
{ "gst", tZONE, -HOUR(10) }, /* Guam Standard, USSR Zone 9 */ |
| 561 |
{ "nzt", tZONE, -HOUR(12) }, /* New Zealand */ |
| 562 |
{ "nzst", tZONE, -HOUR(12) }, /* New Zealand Standard */ |
| 563 |
{ "nzdt", tDAYZONE, -HOUR(12) }, /* New Zealand Daylight */ |
| 564 |
{ "idle", tZONE, -HOUR(12) }, /* International Date Line East */ |
| 565 |
/* ADDED BY Marco Nijdam */ |
| 566 |
{ "dst", tDST, HOUR( 0) }, /* DST on (hour is ignored) */ |
| 567 |
/* End ADDED */ |
| 568 |
{ NULL } |
| 569 |
}; |
| 570 |
|
| 571 |
/* |
| 572 |
* Military timezone table. |
| 573 |
*/ |
| 574 |
static TABLE MilitaryTable[] = { |
| 575 |
{ "a", tZONE, HOUR( 1) }, |
| 576 |
{ "b", tZONE, HOUR( 2) }, |
| 577 |
{ "c", tZONE, HOUR( 3) }, |
| 578 |
{ "d", tZONE, HOUR( 4) }, |
| 579 |
{ "e", tZONE, HOUR( 5) }, |
| 580 |
{ "f", tZONE, HOUR( 6) }, |
| 581 |
{ "g", tZONE, HOUR( 7) }, |
| 582 |
{ "h", tZONE, HOUR( 8) }, |
| 583 |
{ "i", tZONE, HOUR( 9) }, |
| 584 |
{ "k", tZONE, HOUR( 10) }, |
| 585 |
{ "l", tZONE, HOUR( 11) }, |
| 586 |
{ "m", tZONE, HOUR( 12) }, |
| 587 |
{ "n", tZONE, HOUR(- 1) }, |
| 588 |
{ "o", tZONE, HOUR(- 2) }, |
| 589 |
{ "p", tZONE, HOUR(- 3) }, |
| 590 |
{ "q", tZONE, HOUR(- 4) }, |
| 591 |
{ "r", tZONE, HOUR(- 5) }, |
| 592 |
{ "s", tZONE, HOUR(- 6) }, |
| 593 |
{ "t", tZONE, HOUR(- 7) }, |
| 594 |
{ "u", tZONE, HOUR(- 8) }, |
| 595 |
{ "v", tZONE, HOUR(- 9) }, |
| 596 |
{ "w", tZONE, HOUR(-10) }, |
| 597 |
{ "x", tZONE, HOUR(-11) }, |
| 598 |
{ "y", tZONE, HOUR(-12) }, |
| 599 |
{ "z", tZONE, HOUR( 0) }, |
| 600 |
{ NULL } |
| 601 |
}; |
| 602 |
|
| 603 |
|
| 604 |
/* |
| 605 |
* Dump error messages in the bit bucket. |
| 606 |
*/ |
| 607 |
static void |
| 608 |
yyerror(s) |
| 609 |
char *s; |
| 610 |
{ |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
static time_t |
| 615 |
ToSeconds(Hours, Minutes, Seconds, Meridian) |
| 616 |
time_t Hours; |
| 617 |
time_t Minutes; |
| 618 |
time_t Seconds; |
| 619 |
MERIDIAN Meridian; |
| 620 |
{ |
| 621 |
if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59) |
| 622 |
return -1; |
| 623 |
switch (Meridian) { |
| 624 |
case MER24: |
| 625 |
if (Hours < 0 || Hours > 23) |
| 626 |
return -1; |
| 627 |
return (Hours * 60L + Minutes) * 60L + Seconds; |
| 628 |
case MERam: |
| 629 |
if (Hours < 1 || Hours > 12) |
| 630 |
return -1; |
| 631 |
return ((Hours % 12) * 60L + Minutes) * 60L + Seconds; |
| 632 |
case MERpm: |
| 633 |
if (Hours < 1 || Hours > 12) |
| 634 |
return -1; |
| 635 |
return (((Hours % 12) + 12) * 60L + Minutes) * 60L + Seconds; |
| 636 |
} |
| 637 |
return -1; /* Should never be reached */ |
| 638 |
} |
| 639 |
|
| 640 |
/* |
| 641 |
*----------------------------------------------------------------------------- |
| 642 |
* |
| 643 |
* Convert -- |
| 644 |
* |
| 645 |
* Convert a {month, day, year, hours, minutes, seconds, meridian, dst} |
| 646 |
* tuple into a clock seconds value. |
| 647 |
* |
| 648 |
* Results: |
| 649 |
* 0 or -1 indicating success or failure. |
| 650 |
* |
| 651 |
* Side effects: |
| 652 |
* Fills TimePtr with the computed value. |
| 653 |
* |
| 654 |
*----------------------------------------------------------------------------- |
| 655 |
*/ |
| 656 |
static int |
| 657 |
Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode, TimePtr) |
| 658 |
time_t Month; |
| 659 |
time_t Day; |
| 660 |
time_t Year; |
| 661 |
time_t Hours; |
| 662 |
time_t Minutes; |
| 663 |
time_t Seconds; |
| 664 |
MERIDIAN Meridian; |
| 665 |
DSTMODE DSTmode; |
| 666 |
time_t *TimePtr; |
| 667 |
{ |
| 668 |
static int DaysInMonth[12] = { |
| 669 |
31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 |
| 670 |
}; |
| 671 |
time_t tod; |
| 672 |
time_t Julian; |
| 673 |
int i; |
| 674 |
|
| 675 |
/* Figure out how many days are in February for the given year. |
| 676 |
* Every year divisible by 4 is a leap year. |
| 677 |
* But, every year divisible by 100 is not a leap year. |
| 678 |
* But, every year divisible by 400 is a leap year after all. |
| 679 |
*/ |
| 680 |
DaysInMonth[1] = IsLeapYear(Year) ? 29 : 28; |
| 681 |
|
| 682 |
/* Check the inputs for validity */ |
| 683 |
if (Month < 1 || Month > 12 |
| 684 |
|| Year < START_OF_TIME || Year > END_OF_TIME |
| 685 |
|| Day < 1 || Day > DaysInMonth[(int)--Month]) |
| 686 |
return -1; |
| 687 |
|
| 688 |
/* Start computing the value. First determine the number of days |
| 689 |
* represented by the date, then multiply by the number of seconds/day. |
| 690 |
*/ |
| 691 |
for (Julian = Day - 1, i = 0; i < Month; i++) |
| 692 |
Julian += DaysInMonth[i]; |
| 693 |
if (Year >= EPOCH) { |
| 694 |
for (i = EPOCH; i < Year; i++) |
| 695 |
Julian += 365 + IsLeapYear(i); |
| 696 |
} else { |
| 697 |
for (i = Year; i < EPOCH; i++) |
| 698 |
Julian -= 365 + IsLeapYear(i); |
| 699 |
} |
| 700 |
Julian *= SECSPERDAY; |
| 701 |
|
| 702 |
/* Add the timezone offset ?? */ |
| 703 |
Julian += yyTimezone * 60L; |
| 704 |
|
| 705 |
/* Add the number of seconds represented by the time component */ |
| 706 |
if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0) |
| 707 |
return -1; |
| 708 |
Julian += tod; |
| 709 |
|
| 710 |
/* Perform a preliminary DST compensation ?? */ |
| 711 |
if (DSTmode == DSTon |
| 712 |
|| (DSTmode == DSTmaybe && TclpGetDate((TclpTime_t)&Julian, 0)->tm_isdst)) |
| 713 |
Julian -= 60 * 60; |
| 714 |
*TimePtr = Julian; |
| 715 |
return 0; |
| 716 |
} |
| 717 |
|
| 718 |
|
| 719 |
static time_t |
| 720 |
DSTcorrect(Start, Future) |
| 721 |
time_t Start; |
| 722 |
time_t Future; |
| 723 |
{ |
| 724 |
time_t StartDay; |
| 725 |
time_t FutureDay; |
| 726 |
StartDay = (TclpGetDate((TclpTime_t)&Start, 0)->tm_hour + 1) % 24; |
| 727 |
FutureDay = (TclpGetDate((TclpTime_t)&Future, 0)->tm_hour + 1) % 24; |
| 728 |
return (Future - Start) + (StartDay - FutureDay) * 60L * 60L; |
| 729 |
} |
| 730 |
|
| 731 |
|
| 732 |
static time_t |
| 733 |
NamedDay(Start, DayOrdinal, DayNumber) |
| 734 |
time_t Start; |
| 735 |
time_t DayOrdinal; |
| 736 |
time_t DayNumber; |
| 737 |
{ |
| 738 |
struct tm *tm; |
| 739 |
time_t now; |
| 740 |
|
| 741 |
now = Start; |
| 742 |
tm = TclpGetDate((TclpTime_t)&now, 0); |
| 743 |
now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7); |
| 744 |
now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1); |
| 745 |
return DSTcorrect(Start, now); |
| 746 |
} |
| 747 |
|
| 748 |
static time_t |
| 749 |
NamedMonth(Start, MonthOrdinal, MonthNumber) |
| 750 |
time_t Start; |
| 751 |
time_t MonthOrdinal; |
| 752 |
time_t MonthNumber; |
| 753 |
{ |
| 754 |
struct tm *tm; |
| 755 |
time_t now; |
| 756 |
int result; |
| 757 |
|
| 758 |
now = Start; |
| 759 |
tm = TclpGetDate((TclpTime_t)&now, 0); |
| 760 |
/* To compute the next n'th month, we use this alg: |
| 761 |
* add n to year value |
| 762 |
* if currentMonth < requestedMonth decrement year value by 1 (so that |
| 763 |
* doing next february from january gives us february of the current year) |
| 764 |
* set day to 1, time to 0 |
| 765 |
*/ |
| 766 |
tm->tm_year += MonthOrdinal; |
| 767 |
if (tm->tm_mon < MonthNumber - 1) { |
| 768 |
tm->tm_year--; |
| 769 |
} |
| 770 |
result = Convert(MonthNumber, (time_t) 1, tm->tm_year + TM_YEAR_BASE, |
| 771 |
(time_t) 0, (time_t) 0, (time_t) 0, MER24, DSTmaybe, &now); |
| 772 |
if (result < 0) { |
| 773 |
return 0; |
| 774 |
} |
| 775 |
return DSTcorrect(Start, now); |
| 776 |
} |
| 777 |
|
| 778 |
static int |
| 779 |
RelativeMonth(Start, RelMonth, TimePtr) |
| 780 |
time_t Start; |
| 781 |
time_t RelMonth; |
| 782 |
time_t *TimePtr; |
| 783 |
{ |
| 784 |
struct tm *tm; |
| 785 |
time_t Month; |
| 786 |
time_t Year; |
| 787 |
time_t Julian; |
| 788 |
int result; |
| 789 |
|
| 790 |
if (RelMonth == 0) { |
| 791 |
*TimePtr = 0; |
| 792 |
return 0; |
| 793 |
} |
| 794 |
tm = TclpGetDate((TclpTime_t)&Start, 0); |
| 795 |
Month = 12 * (tm->tm_year + TM_YEAR_BASE) + tm->tm_mon + RelMonth; |
| 796 |
Year = Month / 12; |
| 797 |
Month = Month % 12 + 1; |
| 798 |
result = Convert(Month, (time_t) tm->tm_mday, Year, |
| 799 |
(time_t) tm->tm_hour, (time_t) tm->tm_min, (time_t) tm->tm_sec, |
| 800 |
MER24, DSTmaybe, &Julian); |
| 801 |
|
| 802 |
/* |
| 803 |
* The Julian time returned above is behind by one day, if "month" |
| 804 |
* or "year" is used to specify relative time and the GMT flag is true. |
| 805 |
* This problem occurs only when the current time is closer to |
| 806 |
* midnight, the difference being not more than its time difference |
| 807 |
* with GMT. For example, in US/Pacific time zone, the problem occurs |
| 808 |
* whenever the current time is between midnight to 8:00am or 7:00amDST. |
| 809 |
* See Bug# 413397 for more details and sample script. |
| 810 |
* To resolve this bug, we simply add the number of seconds corresponding |
| 811 |
* to timezone difference with GMT to Julian time, if GMT flag is true. |
| 812 |
*/ |
| 813 |
|
| 814 |
if (TclDateTimezone == 0) { |
| 815 |
Julian += TclpGetTimeZone((unsigned long) Start) * 60L; |
| 816 |
} |
| 817 |
|
| 818 |
/* |
| 819 |
* The following iteration takes into account the case were we jump |
| 820 |
* into a "short month". Far example, "one month from Jan 31" will |
| 821 |
* fail because there is no Feb 31. The code below will reduce the |
| 822 |
* day and try converting the date until we succed or the date equals |
| 823 |
* 28 (which always works unless the date is bad in another way). |
| 824 |
*/ |
| 825 |
|
| 826 |
while ((result != 0) && (tm->tm_mday > 28)) { |
| 827 |
tm->tm_mday--; |
| 828 |
result = Convert(Month, (time_t) tm->tm_mday, Year, |
| 829 |
(time_t) tm->tm_hour, (time_t) tm->tm_min, (time_t) tm->tm_sec, |
| 830 |
MER24, DSTmaybe, &Julian); |
| 831 |
} |
| 832 |
if (result != 0) { |
| 833 |
return -1; |
| 834 |
} |
| 835 |
*TimePtr = DSTcorrect(Start, Julian); |
| 836 |
return 0; |
| 837 |
} |
| 838 |
|
| 839 |
|
| 840 |
/* |
| 841 |
*----------------------------------------------------------------------------- |
| 842 |
* |
| 843 |
* RelativeDay -- |
| 844 |
* |
| 845 |
* Given a starting time and a number of days before or after, compute the |
| 846 |
* DST corrected difference between those dates. |
| 847 |
* |
| 848 |
* Results: |
| 849 |
* 1 or -1 indicating success or failure. |
| 850 |
* |
| 851 |
* Side effects: |
| 852 |
* Fills TimePtr with the computed value. |
| 853 |
* |
| 854 |
*----------------------------------------------------------------------------- |
| 855 |
*/ |
| 856 |
|
| 857 |
static int |
| 858 |
RelativeDay(Start, RelDay, TimePtr) |
| 859 |
time_t Start; |
| 860 |
time_t RelDay; |
| 861 |
time_t *TimePtr; |
| 862 |
{ |
| 863 |
time_t new; |
| 864 |
|
| 865 |
new = Start + (RelDay * 60 * 60 * 24); |
| 866 |
*TimePtr = DSTcorrect(Start, new); |
| 867 |
return 1; |
| 868 |
} |
| 869 |
|
| 870 |
static int |
| 871 |
LookupWord(buff) |
| 872 |
char *buff; |
| 873 |
{ |
| 874 |
register char *p; |
| 875 |
register char *q; |
| 876 |
register TABLE *tp; |
| 877 |
int i; |
| 878 |
int abbrev; |
| 879 |
|
| 880 |
/* |
| 881 |
* Make it lowercase. |
| 882 |
*/ |
| 883 |
|
| 884 |
Tcl_UtfToLower(buff); |
| 885 |
|
| 886 |
if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) { |
| 887 |
yylval.Meridian = MERam; |
| 888 |
return tMERIDIAN; |
| 889 |
} |
| 890 |
if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) { |
| 891 |
yylval.Meridian = MERpm; |
| 892 |
return tMERIDIAN; |
| 893 |
} |
| 894 |
|
| 895 |
/* |
| 896 |
* See if we have an abbreviation for a month. |
| 897 |
*/ |
| 898 |
if (strlen(buff) == 3) { |
| 899 |
abbrev = 1; |
| 900 |
} else if (strlen(buff) == 4 && buff[3] == '.') { |
| 901 |
abbrev = 1; |
| 902 |
buff[3] = '\0'; |
| 903 |
} else { |
| 904 |
abbrev = 0; |
| 905 |
} |
| 906 |
|
| 907 |
for (tp = MonthDayTable; tp->name; tp++) { |
| 908 |
if (abbrev) { |
| 909 |
if (strncmp(buff, tp->name, 3) == 0) { |
| 910 |
yylval.Number = tp->value; |
| 911 |
return tp->type; |
| 912 |
} |
| 913 |
} else if (strcmp(buff, tp->name) == 0) { |
| 914 |
yylval.Number = tp->value; |
| 915 |
return tp->type; |
| 916 |
} |
| 917 |
} |
| 918 |
|
| 919 |
for (tp = TimezoneTable; tp->name; tp++) { |
| 920 |
if (strcmp(buff, tp->name) == 0) { |
| 921 |
yylval.Number = tp->value; |
| 922 |
return tp->type; |
| 923 |
} |
| 924 |
} |
| 925 |
|
| 926 |
for (tp = UnitsTable; tp->name; tp++) { |
| 927 |
if (strcmp(buff, tp->name) == 0) { |
| 928 |
yylval.Number = tp->value; |
| 929 |
return tp->type; |
| 930 |
} |
| 931 |
} |
| 932 |
|
| 933 |
/* |
| 934 |
* Strip off any plural and try the units table again. |
| 935 |
*/ |
| 936 |
i = strlen(buff) - 1; |
| 937 |
if (buff[i] == 's') { |
| 938 |
buff[i] = '\0'; |
| 939 |
for (tp = UnitsTable; tp->name; tp++) { |
| 940 |
if (strcmp(buff, tp->name) == 0) { |
| 941 |
yylval.Number = tp->value; |
| 942 |
return tp->type; |
| 943 |
} |
| 944 |
} |
| 945 |
} |
| 946 |
|
| 947 |
for (tp = OtherTable; tp->name; tp++) { |
| 948 |
if (strcmp(buff, tp->name) == 0) { |
| 949 |
yylval.Number = tp->value; |
| 950 |
return tp->type; |
| 951 |
} |
| 952 |
} |
| 953 |
|
| 954 |
/* |
| 955 |
* Military timezones. |
| 956 |
*/ |
| 957 |
if (buff[1] == '\0' && !(*buff & 0x80) |
| 958 |
&& isalpha(UCHAR(*buff))) { /* INTL: ISO only */ |
| 959 |
for (tp = MilitaryTable; tp->name; tp++) { |
| 960 |
if (strcmp(buff, tp->name) == 0) { |
| 961 |
yylval.Number = tp->value; |
| 962 |
return tp->type; |
| 963 |
} |
| 964 |
} |
| 965 |
} |
| 966 |
|
| 967 |
/* |
| 968 |
* Drop out any periods and try the timezone table again. |
| 969 |
*/ |
| 970 |
for (i = 0, p = q = buff; *q; q++) |
| 971 |
if (*q != '.') { |
| 972 |
*p++ = *q; |
| 973 |
} else { |
| 974 |
i++; |
| 975 |
} |
| 976 |
*p = '\0'; |
| 977 |
if (i) { |
| 978 |
for (tp = TimezoneTable; tp->name; tp++) { |
| 979 |
if (strcmp(buff, tp->name) == 0) { |
| 980 |
yylval.Number = tp->value; |
| 981 |
return tp->type; |
| 982 |
} |
| 983 |
} |
| 984 |
} |
| 985 |
|
| 986 |
return tID; |
| 987 |
} |
| 988 |
|
| 989 |
|
| 990 |
static int |
| 991 |
yylex() |
| 992 |
{ |
| 993 |
register char c; |
| 994 |
register char *p; |
| 995 |
char buff[20]; |
| 996 |
int Count; |
| 997 |
|
| 998 |
for ( ; ; ) { |
| 999 |
while (isspace(UCHAR(*yyInput))) { |
| 1000 |
yyInput++; |
| 1001 |
} |
| 1002 |
|
| 1003 |
if (isdigit(UCHAR(c = *yyInput))) { /* INTL: digit */ |
| 1004 |
/* convert the string into a number; count the number of digits */ |
| 1005 |
Count = 0; |
| 1006 |
for (yylval.Number = 0; |
| 1007 |
isdigit(UCHAR(c = *yyInput++)); ) { /* INTL: digit */ |
| 1008 |
yylval.Number = 10 * yylval.Number + c - '0'; |
| 1009 |
Count++; |
| 1010 |
} |
| 1011 |
yyInput--; |
| 1012 |
/* A number with 6 or more digits is considered an ISO 8601 base */ |
| 1013 |
if (Count >= 6) { |
| 1014 |
return tISOBASE; |
| 1015 |
} else { |
| 1016 |
return tUNUMBER; |
| 1017 |
} |
| 1018 |
} |
| 1019 |
if (!(c & 0x80) && isalpha(UCHAR(c))) { /* INTL: ISO only. */ |
| 1020 |
for (p = buff; isalpha(UCHAR(c = *yyInput++)) /* INTL: ISO only. */ |
| 1021 |
|| c == '.'; ) { |
| 1022 |
if (p < &buff[sizeof buff - 1]) { |
| 1023 |
*p++ = c; |
| 1024 |
} |
| 1025 |
} |
| 1026 |
*p = '\0'; |
| 1027 |
yyInput--; |
| 1028 |
return LookupWord(buff); |
| 1029 |
} |
| 1030 |
if (c != '(') { |
| 1031 |
return *yyInput++; |
| 1032 |
} |
| 1033 |
Count = 0; |
| 1034 |
do { |
| 1035 |
c = *yyInput++; |
| 1036 |
if (c == '\0') { |
| 1037 |
return c; |
| 1038 |
} else if (c == '(') { |
| 1039 |
Count++; |
| 1040 |
} else if (c == ')') { |
| 1041 |
Count--; |
| 1042 |
} |
| 1043 |
} while (Count > 0); |
| 1044 |
} |
| 1045 |
} |
| 1046 |
|
| 1047 |
/* |
| 1048 |
* Specify zone is of -50000 to force GMT. (This allows BST to work). |
| 1049 |
*/ |
| 1050 |
|
| 1051 |
int |
| 1052 |
TclGetDate(p, now, zone, timePtr) |
| 1053 |
char *p; |
| 1054 |
unsigned long now; |
| 1055 |
long zone; |
| 1056 |
unsigned long *timePtr; |
| 1057 |
{ |
| 1058 |
struct tm *tm; |
| 1059 |
time_t Start; |
| 1060 |
time_t Time; |
| 1061 |
time_t tod; |
| 1062 |
int thisyear; |
| 1063 |
|
| 1064 |
yyInput = p; |
| 1065 |
/* now has to be cast to a time_t for 64bit compliance */ |
| 1066 |
Start = now; |
| 1067 |
tm = TclpGetDate((TclpTime_t) &Start, 0); |
| 1068 |
thisyear = tm->tm_year + TM_YEAR_BASE; |
| 1069 |
yyYear = thisyear; |
| 1070 |
yyMonth = tm->tm_mon + 1; |
| 1071 |
yyDay = tm->tm_mday; |
| 1072 |
yyTimezone = zone; |
| 1073 |
if (zone == -50000) { |
| 1074 |
yyDSTmode = DSToff; /* assume GMT */ |
| 1075 |
yyTimezone = 0; |
| 1076 |
} else { |
| 1077 |
yyDSTmode = DSTmaybe; |
| 1078 |
} |
| 1079 |
yyHour = 0; |
| 1080 |
yyMinutes = 0; |
| 1081 |
yySeconds = 0; |
| 1082 |
yyMeridian = MER24; |
| 1083 |
yyRelSeconds = 0; |
| 1084 |
yyRelMonth = 0; |
| 1085 |
yyRelDay = 0; |
| 1086 |
yyRelPointer = NULL; |
| 1087 |
|
| 1088 |
yyHaveDate = 0; |
| 1089 |
yyHaveDay = 0; |
| 1090 |
yyHaveOrdinalMonth = 0; |
| 1091 |
yyHaveRel = 0; |
| 1092 |
yyHaveTime = 0; |
| 1093 |
yyHaveZone = 0; |
| 1094 |
|
| 1095 |
if (yyparse() || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || |
| 1096 |
yyHaveDay > 1 || yyHaveOrdinalMonth > 1) { |
| 1097 |
return -1; |
| 1098 |
} |
| 1099 |
|
| 1100 |
if (yyHaveDate || yyHaveTime || yyHaveDay) { |
| 1101 |
if (TclDateYear < 0) { |
| 1102 |
TclDateYear = -TclDateYear; |
| 1103 |
} |
| 1104 |
/* |
| 1105 |
* The following line handles years that are specified using |
| 1106 |
* only two digits. The line of code below implements a policy |
| 1107 |
* defined by the X/Open workgroup on the millinium rollover. |
| 1108 |
* Note: some of those dates may not actually be valid on some |
| 1109 |
* platforms. The POSIX standard startes that the dates 70-99 |
| 1110 |
* shall refer to 1970-1999 and 00-38 shall refer to 2000-2038. |
| 1111 |
* This later definition should work on all platforms. |
| 1112 |
*/ |
| 1113 |
|
| 1114 |
if (TclDateYear < 100) { |
| 1115 |
if (TclDateYear >= 69) { |
| 1116 |
TclDateYear += 1900; |
| 1117 |
} else { |
| 1118 |
TclDateYear += 2000; |
| 1119 |
} |
| 1120 |
} |
| 1121 |
if (Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds, |
| 1122 |
yyMeridian, yyDSTmode, &Start) < 0) { |
| 1123 |
return -1; |
| 1124 |
} |
| 1125 |
} else { |
| 1126 |
Start = now; |
| 1127 |
if (!yyHaveRel) { |
| 1128 |
Start -= ((tm->tm_hour * 60L * 60L) + |
| 1129 |
tm->tm_min * 60L) + tm->tm_sec; |
| 1130 |
} |
| 1131 |
} |
| 1132 |
|
| 1133 |
Start += yyRelSeconds; |
| 1134 |
if (RelativeMonth(Start, yyRelMonth, &Time) < 0) { |
| 1135 |
return -1; |
| 1136 |
} |
| 1137 |
Start += Time; |
| 1138 |
|
| 1139 |
if (RelativeDay(Start, yyRelDay, &Time) < 0) { |
| 1140 |
return -1; |
| 1141 |
} |
| 1142 |
Start += Time; |
| 1143 |
|
| 1144 |
if (yyHaveDay && !yyHaveDate) { |
| 1145 |
tod = NamedDay(Start, yyDayOrdinal, yyDayNumber); |
| 1146 |
Start += tod; |
| 1147 |
} |
| 1148 |
|
| 1149 |
if (yyHaveOrdinalMonth) { |
| 1150 |
tod = NamedMonth(Start, yyMonthOrdinal, yyMonth); |
| 1151 |
Start += tod; |
| 1152 |
} |
| 1153 |
|
| 1154 |
*timePtr = Start; |
| 1155 |
return 0; |
| 1156 |
} |