PageRenderTime 62ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/opensource.apple.com/source/tcl/tcl-87/tcl/tcl/generic/tclGetDate.y

#
Happy | 1067 lines | 964 code | 103 blank | 0 comment | 0 complexity | 7667cec337fa13b711809326b99a71ff MD5 | raw file
Possible License(s): LGPL-2.0, MPL-2.0, GPL-2.0, ISC, LGPL-2.1, Apache-2.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause, WTFPL, MIT, AGPL-1.0, AGPL-3.0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>tclGetDate.y</title>
  6. <style type="text/css">
  7. .enscript-comment { font-style: italic; color: rgb(178,34,34); }
  8. .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
  9. .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
  10. .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
  11. .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
  12. .enscript-string { font-weight: bold; color: rgb(188,143,143); }
  13. .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
  14. .enscript-type { font-weight: bold; color: rgb(34,139,34); }
  15. .enscript-highlight { text-decoration: underline; color: 0; }
  16. </style>
  17. </head>
  18. <body id="top">
  19. <h1 style="margin:8px;" id="f1">tclGetDate.y&nbsp;&nbsp;&nbsp;<span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
  20. <hr/>
  21. <div></div>
  22. <pre>
  23. /*
  24. * tclGetDate.y --
  25. *
  26. * Contains yacc grammar for parsing date and time strings. The output of
  27. * this file should be the file tclDate.c which is used directly in the
  28. * Tcl sources. Note that this file is largely obsolete in Tcl 8.5; it is
  29. * only used when doing free-form date parsing, an ill-defined process
  30. * anyway.
  31. *
  32. * Copyright (c) 1992-1995 Karl Lehenbauer and Mark Diekhans.
  33. * Copyright (c) 1995-1997 Sun Microsystems, Inc.
  34. *
  35. * See the file &quot;license.terms&quot; for information on usage and redistribution of
  36. * this file, and for a DISCLAIMER OF ALL WARRANTIES.
  37. *
  38. * RCS: @(#) $Id: tclGetDate.y,v 1.38 2007/12/13 15:23:17 dgp Exp $
  39. */
  40. %{
  41. /*
  42. * tclDate.c --
  43. *
  44. * This file is generated from a yacc grammar defined in the file
  45. * tclGetDate.y. It should not be edited directly.
  46. *
  47. * Copyright (c) 1992-1995 Karl Lehenbauer and Mark Diekhans.
  48. * Copyright (c) 1995-1997 Sun Microsystems, Inc.
  49. *
  50. * See the file &quot;license.terms&quot; for information on usage and redistribution of
  51. * this file, and for a DISCLAIMER OF ALL WARRANTIES.
  52. *
  53. */
  54. #include &quot;tclInt.h&quot;
  55. /*
  56. * Bison generates several labels that happen to be unused. MS Visual C++
  57. * doesn't like that, and complains. Tell it to shut up.
  58. */
  59. #ifdef _MSC_VER
  60. #pragma warning( disable : 4102 )
  61. #endif /* _MSC_VER */
  62. /*
  63. * yyparse will accept a 'struct DateInfo' as its parameter; that's where the
  64. * parsed fields will be returned.
  65. */
  66. typedef struct DateInfo {
  67. time_t dateYear;
  68. time_t dateMonth;
  69. time_t dateDay;
  70. int dateHaveDate;
  71. time_t dateHour;
  72. time_t dateMinutes;
  73. time_t dateSeconds;
  74. int dateMeridian;
  75. int dateHaveTime;
  76. time_t dateTimezone;
  77. int dateDSTmode;
  78. int dateHaveZone;
  79. time_t dateRelMonth;
  80. time_t dateRelDay;
  81. time_t dateRelSeconds;
  82. int dateHaveRel;
  83. time_t dateMonthOrdinal;
  84. int dateHaveOrdinalMonth;
  85. time_t dateDayOrdinal;
  86. time_t dateDayNumber;
  87. int dateHaveDay;
  88. char *dateInput;
  89. time_t *dateRelPointer;
  90. int dateDigitCount;
  91. } DateInfo;
  92. #define YYPARSE_PARAM info
  93. #define YYLEX_PARAM info
  94. #define YYMALLOC ckalloc
  95. #define YYFREE(x) (ckfree((void*) (x)))
  96. #define yyDSTmode (((DateInfo *) info)-&gt;dateDSTmode)
  97. #define yyDayOrdinal (((DateInfo *) info)-&gt;dateDayOrdinal)
  98. #define yyDayNumber (((DateInfo *) info)-&gt;dateDayNumber)
  99. #define yyMonthOrdinal (((DateInfo *) info)-&gt;dateMonthOrdinal)
  100. #define yyHaveDate (((DateInfo *) info)-&gt;dateHaveDate)
  101. #define yyHaveDay (((DateInfo *) info)-&gt;dateHaveDay)
  102. #define yyHaveOrdinalMonth (((DateInfo *) info)-&gt;dateHaveOrdinalMonth)
  103. #define yyHaveRel (((DateInfo *) info)-&gt;dateHaveRel)
  104. #define yyHaveTime (((DateInfo *) info)-&gt;dateHaveTime)
  105. #define yyHaveZone (((DateInfo *) info)-&gt;dateHaveZone)
  106. #define yyTimezone (((DateInfo *) info)-&gt;dateTimezone)
  107. #define yyDay (((DateInfo *) info)-&gt;dateDay)
  108. #define yyMonth (((DateInfo *) info)-&gt;dateMonth)
  109. #define yyYear (((DateInfo *) info)-&gt;dateYear)
  110. #define yyHour (((DateInfo *) info)-&gt;dateHour)
  111. #define yyMinutes (((DateInfo *) info)-&gt;dateMinutes)
  112. #define yySeconds (((DateInfo *) info)-&gt;dateSeconds)
  113. #define yyMeridian (((DateInfo *) info)-&gt;dateMeridian)
  114. #define yyRelMonth (((DateInfo *) info)-&gt;dateRelMonth)
  115. #define yyRelDay (((DateInfo *) info)-&gt;dateRelDay)
  116. #define yyRelSeconds (((DateInfo *) info)-&gt;dateRelSeconds)
  117. #define yyRelPointer (((DateInfo *) info)-&gt;dateRelPointer)
  118. #define yyInput (((DateInfo *) info)-&gt;dateInput)
  119. #define yyDigitCount (((DateInfo *) info)-&gt;dateDigitCount)
  120. #define EPOCH 1970
  121. #define START_OF_TIME 1902
  122. #define END_OF_TIME 2037
  123. /*
  124. * The offset of tm_year of struct tm returned by localtime, gmtime, etc.
  125. * Posix requires 1900.
  126. */
  127. #define TM_YEAR_BASE 1900
  128. #define HOUR(x) ((int) (60 * x))
  129. #define SECSPERDAY (24L * 60L * 60L)
  130. #define IsLeapYear(x) ((x % 4 == 0) &amp;&amp; (x % 100 != 0 || x % 400 == 0))
  131. /*
  132. * An entry in the lexical lookup table.
  133. */
  134. typedef struct _TABLE {
  135. char *name;
  136. int type;
  137. time_t value;
  138. } TABLE;
  139. /*
  140. * Daylight-savings mode: on, off, or not yet known.
  141. */
  142. typedef enum _DSTMODE {
  143. DSTon, DSToff, DSTmaybe
  144. } DSTMODE;
  145. /*
  146. * Meridian: am, pm, or 24-hour style.
  147. */
  148. typedef enum _MERIDIAN {
  149. MERam, MERpm, MER24
  150. } MERIDIAN;
  151. /*
  152. * Prototypes of internal functions.
  153. */
  154. static int LookupWord(char *buff);
  155. static void TclDateerror(char *s);
  156. static int TclDatelex(void *info);
  157. static time_t ToSeconds(time_t Hours, time_t Minutes,
  158. time_t Seconds, MERIDIAN Meridian);
  159. MODULE_SCOPE int yyparse(void *);
  160. %}
  161. %union {
  162. time_t Number;
  163. enum _MERIDIAN Meridian;
  164. }
  165. %token tAGO tDAY tDAYZONE tID tMERIDIAN tMINUTE_UNIT tMONTH tMONTH_UNIT
  166. %token tSTARDATE tSEC_UNIT tSNUMBER tUNUMBER tZONE tEPOCH tDST tISOBASE
  167. %token tDAY_UNIT tNEXT
  168. %type &lt;Number&gt; tDAY tDAYZONE tMINUTE_UNIT tMONTH tMONTH_UNIT tDST
  169. %type &lt;Number&gt; tSEC_UNIT tSNUMBER tUNUMBER tZONE tISOBASE tDAY_UNIT
  170. %type &lt;Number&gt; unit sign tNEXT tSTARDATE
  171. %type &lt;Meridian&gt; tMERIDIAN o_merid
  172. %%
  173. spec : /* NULL */
  174. | spec item
  175. ;
  176. item : time {
  177. yyHaveTime++;
  178. }
  179. | zone {
  180. yyHaveZone++;
  181. }
  182. | date {
  183. yyHaveDate++;
  184. }
  185. | ordMonth {
  186. yyHaveOrdinalMonth++;
  187. }
  188. | day {
  189. yyHaveDay++;
  190. }
  191. | relspec {
  192. yyHaveRel++;
  193. }
  194. | iso {
  195. yyHaveTime++;
  196. yyHaveDate++;
  197. }
  198. | trek {
  199. yyHaveTime++;
  200. yyHaveDate++;
  201. yyHaveRel++;
  202. }
  203. | number
  204. ;
  205. time : tUNUMBER tMERIDIAN {
  206. yyHour = $1;
  207. yyMinutes = 0;
  208. yySeconds = 0;
  209. yyMeridian = $2;
  210. }
  211. | tUNUMBER ':' tUNUMBER o_merid {
  212. yyHour = $1;
  213. yyMinutes = $3;
  214. yySeconds = 0;
  215. yyMeridian = $4;
  216. }
  217. | tUNUMBER ':' tUNUMBER '-' tUNUMBER {
  218. yyHour = $1;
  219. yyMinutes = $3;
  220. yyMeridian = MER24;
  221. yyDSTmode = DSToff;
  222. yyTimezone = ($5 % 100 + ($5 / 100) * 60);
  223. ++yyHaveZone;
  224. }
  225. | tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid {
  226. yyHour = $1;
  227. yyMinutes = $3;
  228. yySeconds = $5;
  229. yyMeridian = $6;
  230. }
  231. | tUNUMBER ':' tUNUMBER ':' tUNUMBER '-' tUNUMBER {
  232. yyHour = $1;
  233. yyMinutes = $3;
  234. yySeconds = $5;
  235. yyMeridian = MER24;
  236. yyDSTmode = DSToff;
  237. yyTimezone = ($7 % 100 + ($7 / 100) * 60);
  238. ++yyHaveZone;
  239. }
  240. ;
  241. zone : tZONE tDST {
  242. yyTimezone = $1;
  243. yyDSTmode = DSTon;
  244. }
  245. | tZONE {
  246. yyTimezone = $1;
  247. yyDSTmode = DSToff;
  248. }
  249. | tDAYZONE {
  250. yyTimezone = $1;
  251. yyDSTmode = DSTon;
  252. }
  253. ;
  254. day : tDAY {
  255. yyDayOrdinal = 1;
  256. yyDayNumber = $1;
  257. }
  258. | tDAY ',' {
  259. yyDayOrdinal = 1;
  260. yyDayNumber = $1;
  261. }
  262. | tUNUMBER tDAY {
  263. yyDayOrdinal = $1;
  264. yyDayNumber = $2;
  265. }
  266. | sign tUNUMBER tDAY {
  267. yyDayOrdinal = $1 * $2;
  268. yyDayNumber = $3;
  269. }
  270. | tNEXT tDAY {
  271. yyDayOrdinal = 2;
  272. yyDayNumber = $2;
  273. }
  274. ;
  275. date : tUNUMBER '/' tUNUMBER {
  276. yyMonth = $1;
  277. yyDay = $3;
  278. }
  279. | tUNUMBER '/' tUNUMBER '/' tUNUMBER {
  280. yyMonth = $1;
  281. yyDay = $3;
  282. yyYear = $5;
  283. }
  284. | tISOBASE {
  285. yyYear = $1 / 10000;
  286. yyMonth = ($1 % 10000)/100;
  287. yyDay = $1 % 100;
  288. }
  289. | tUNUMBER '-' tMONTH '-' tUNUMBER {
  290. yyDay = $1;
  291. yyMonth = $3;
  292. yyYear = $5;
  293. }
  294. | tUNUMBER '-' tUNUMBER '-' tUNUMBER {
  295. yyMonth = $3;
  296. yyDay = $5;
  297. yyYear = $1;
  298. }
  299. | tMONTH tUNUMBER {
  300. yyMonth = $1;
  301. yyDay = $2;
  302. }
  303. | tMONTH tUNUMBER ',' tUNUMBER {
  304. yyMonth = $1;
  305. yyDay = $2;
  306. yyYear = $4;
  307. }
  308. | tUNUMBER tMONTH {
  309. yyMonth = $2;
  310. yyDay = $1;
  311. }
  312. | tEPOCH {
  313. yyMonth = 1;
  314. yyDay = 1;
  315. yyYear = EPOCH;
  316. }
  317. | tUNUMBER tMONTH tUNUMBER {
  318. yyMonth = $2;
  319. yyDay = $1;
  320. yyYear = $3;
  321. }
  322. ;
  323. ordMonth: tNEXT tMONTH {
  324. yyMonthOrdinal = 1;
  325. yyMonth = $2;
  326. }
  327. | tNEXT tUNUMBER tMONTH {
  328. yyMonthOrdinal = $2;
  329. yyMonth = $3;
  330. }
  331. ;
  332. iso : tISOBASE tZONE tISOBASE {
  333. if ($2 != HOUR( 7)) YYABORT;
  334. yyYear = $1 / 10000;
  335. yyMonth = ($1 % 10000)/100;
  336. yyDay = $1 % 100;
  337. yyHour = $3 / 10000;
  338. yyMinutes = ($3 % 10000)/100;
  339. yySeconds = $3 % 100;
  340. }
  341. | tISOBASE tZONE tUNUMBER ':' tUNUMBER ':' tUNUMBER {
  342. if ($2 != HOUR( 7)) YYABORT;
  343. yyYear = $1 / 10000;
  344. yyMonth = ($1 % 10000)/100;
  345. yyDay = $1 % 100;
  346. yyHour = $3;
  347. yyMinutes = $5;
  348. yySeconds = $7;
  349. }
  350. | tISOBASE tISOBASE {
  351. yyYear = $1 / 10000;
  352. yyMonth = ($1 % 10000)/100;
  353. yyDay = $1 % 100;
  354. yyHour = $2 / 10000;
  355. yyMinutes = ($2 % 10000)/100;
  356. yySeconds = $2 % 100;
  357. }
  358. ;
  359. trek : tSTARDATE tUNUMBER '.' tUNUMBER {
  360. /*
  361. * Offset computed year by -377 so that the returned years will be
  362. * in a range accessible with a 32 bit clock seconds value.
  363. */
  364. yyYear = $2/1000 + 2323 - 377;
  365. yyDay = 1;
  366. yyMonth = 1;
  367. yyRelDay += (($2%1000)*(365 + IsLeapYear(yyYear)))/1000;
  368. yyRelSeconds += $4 * 144 * 60;
  369. }
  370. ;
  371. relspec : relunits tAGO {
  372. yyRelSeconds *= -1;
  373. yyRelMonth *= -1;
  374. yyRelDay *= -1;
  375. }
  376. | relunits
  377. ;
  378. relunits : sign tUNUMBER unit {
  379. *yyRelPointer += $1 * $2 * $3;
  380. }
  381. | tUNUMBER unit {
  382. *yyRelPointer += $1 * $2;
  383. }
  384. | tNEXT unit {
  385. *yyRelPointer += $2;
  386. }
  387. | tNEXT tUNUMBER unit {
  388. *yyRelPointer += $2 * $3;
  389. }
  390. | unit {
  391. *yyRelPointer += $1;
  392. }
  393. ;
  394. sign : '-' {
  395. $$ = -1;
  396. }
  397. | '+' {
  398. $$ = 1;
  399. }
  400. ;
  401. unit : tSEC_UNIT {
  402. $$ = $1;
  403. yyRelPointer = &amp;yyRelSeconds;
  404. }
  405. | tDAY_UNIT {
  406. $$ = $1;
  407. yyRelPointer = &amp;yyRelDay;
  408. }
  409. | tMONTH_UNIT {
  410. $$ = $1;
  411. yyRelPointer = &amp;yyRelMonth;
  412. }
  413. ;
  414. number : tUNUMBER {
  415. if (yyHaveTime &amp;&amp; yyHaveDate &amp;&amp; !yyHaveRel) {
  416. yyYear = $1;
  417. } else {
  418. yyHaveTime++;
  419. if (yyDigitCount &lt;= 2) {
  420. yyHour = $1;
  421. yyMinutes = 0;
  422. } else {
  423. yyHour = $1 / 100;
  424. yyMinutes = $1 % 100;
  425. }
  426. yySeconds = 0;
  427. yyMeridian = MER24;
  428. }
  429. }
  430. ;
  431. o_merid : /* NULL */ {
  432. $$ = MER24;
  433. }
  434. | tMERIDIAN {
  435. $$ = $1;
  436. }
  437. ;
  438. %%
  439. MODULE_SCOPE int yychar;
  440. MODULE_SCOPE YYSTYPE yylval;
  441. MODULE_SCOPE int yynerrs;
  442. /*
  443. * Month and day table.
  444. */
  445. static TABLE MonthDayTable[] = {
  446. { &quot;january&quot;, tMONTH, 1 },
  447. { &quot;february&quot;, tMONTH, 2 },
  448. { &quot;march&quot;, tMONTH, 3 },
  449. { &quot;april&quot;, tMONTH, 4 },
  450. { &quot;may&quot;, tMONTH, 5 },
  451. { &quot;june&quot;, tMONTH, 6 },
  452. { &quot;july&quot;, tMONTH, 7 },
  453. { &quot;august&quot;, tMONTH, 8 },
  454. { &quot;september&quot;, tMONTH, 9 },
  455. { &quot;sept&quot;, tMONTH, 9 },
  456. { &quot;october&quot;, tMONTH, 10 },
  457. { &quot;november&quot;, tMONTH, 11 },
  458. { &quot;december&quot;, tMONTH, 12 },
  459. { &quot;sunday&quot;, tDAY, 0 },
  460. { &quot;monday&quot;, tDAY, 1 },
  461. { &quot;tuesday&quot;, tDAY, 2 },
  462. { &quot;tues&quot;, tDAY, 2 },
  463. { &quot;wednesday&quot;, tDAY, 3 },
  464. { &quot;wednes&quot;, tDAY, 3 },
  465. { &quot;thursday&quot;, tDAY, 4 },
  466. { &quot;thur&quot;, tDAY, 4 },
  467. { &quot;thurs&quot;, tDAY, 4 },
  468. { &quot;friday&quot;, tDAY, 5 },
  469. { &quot;saturday&quot;, tDAY, 6 },
  470. { NULL }
  471. };
  472. /*
  473. * Time units table.
  474. */
  475. static TABLE UnitsTable[] = {
  476. { &quot;year&quot;, tMONTH_UNIT, 12 },
  477. { &quot;month&quot;, tMONTH_UNIT, 1 },
  478. { &quot;fortnight&quot;, tDAY_UNIT, 14 },
  479. { &quot;week&quot;, tDAY_UNIT, 7 },
  480. { &quot;day&quot;, tDAY_UNIT, 1 },
  481. { &quot;hour&quot;, tSEC_UNIT, 60 * 60 },
  482. { &quot;minute&quot;, tSEC_UNIT, 60 },
  483. { &quot;min&quot;, tSEC_UNIT, 60 },
  484. { &quot;second&quot;, tSEC_UNIT, 1 },
  485. { &quot;sec&quot;, tSEC_UNIT, 1 },
  486. { NULL }
  487. };
  488. /*
  489. * Assorted relative-time words.
  490. */
  491. static TABLE OtherTable[] = {
  492. { &quot;tomorrow&quot;, tDAY_UNIT, 1 },
  493. { &quot;yesterday&quot;, tDAY_UNIT, -1 },
  494. { &quot;today&quot;, tDAY_UNIT, 0 },
  495. { &quot;now&quot;, tSEC_UNIT, 0 },
  496. { &quot;last&quot;, tUNUMBER, -1 },
  497. { &quot;this&quot;, tSEC_UNIT, 0 },
  498. { &quot;next&quot;, tNEXT, 1 },
  499. #if 0
  500. { &quot;first&quot;, tUNUMBER, 1 },
  501. { &quot;second&quot;, tUNUMBER, 2 },
  502. { &quot;third&quot;, tUNUMBER, 3 },
  503. { &quot;fourth&quot;, tUNUMBER, 4 },
  504. { &quot;fifth&quot;, tUNUMBER, 5 },
  505. { &quot;sixth&quot;, tUNUMBER, 6 },
  506. { &quot;seventh&quot;, tUNUMBER, 7 },
  507. { &quot;eighth&quot;, tUNUMBER, 8 },
  508. { &quot;ninth&quot;, tUNUMBER, 9 },
  509. { &quot;tenth&quot;, tUNUMBER, 10 },
  510. { &quot;eleventh&quot;, tUNUMBER, 11 },
  511. { &quot;twelfth&quot;, tUNUMBER, 12 },
  512. #endif
  513. { &quot;ago&quot;, tAGO, 1 },
  514. { &quot;epoch&quot;, tEPOCH, 0 },
  515. { &quot;stardate&quot;, tSTARDATE, 0 },
  516. { NULL }
  517. };
  518. /*
  519. * The timezone table. (Note: This table was modified to not use any floating
  520. * point constants to work around an SGI compiler bug).
  521. */
  522. static TABLE TimezoneTable[] = {
  523. { &quot;gmt&quot;, tZONE, HOUR( 0) }, /* Greenwich Mean */
  524. { &quot;ut&quot;, tZONE, HOUR( 0) }, /* Universal (Coordinated) */
  525. { &quot;utc&quot;, tZONE, HOUR( 0) },
  526. { &quot;uct&quot;, tZONE, HOUR( 0) }, /* Universal Coordinated Time */
  527. { &quot;wet&quot;, tZONE, HOUR( 0) }, /* Western European */
  528. { &quot;bst&quot;, tDAYZONE, HOUR( 0) }, /* British Summer */
  529. { &quot;wat&quot;, tZONE, HOUR( 1) }, /* West Africa */
  530. { &quot;at&quot;, tZONE, HOUR( 2) }, /* Azores */
  531. #if 0
  532. /* For completeness. BST is also British Summer, and GST is
  533. * also Guam Standard. */
  534. { &quot;bst&quot;, tZONE, HOUR( 3) }, /* Brazil Standard */
  535. { &quot;gst&quot;, tZONE, HOUR( 3) }, /* Greenland Standard */
  536. #endif
  537. { &quot;nft&quot;, tZONE, HOUR( 7/2) }, /* Newfoundland */
  538. { &quot;nst&quot;, tZONE, HOUR( 7/2) }, /* Newfoundland Standard */
  539. { &quot;ndt&quot;, tDAYZONE, HOUR( 7/2) }, /* Newfoundland Daylight */
  540. { &quot;ast&quot;, tZONE, HOUR( 4) }, /* Atlantic Standard */
  541. { &quot;adt&quot;, tDAYZONE, HOUR( 4) }, /* Atlantic Daylight */
  542. { &quot;est&quot;, tZONE, HOUR( 5) }, /* Eastern Standard */
  543. { &quot;edt&quot;, tDAYZONE, HOUR( 5) }, /* Eastern Daylight */
  544. { &quot;cst&quot;, tZONE, HOUR( 6) }, /* Central Standard */
  545. { &quot;cdt&quot;, tDAYZONE, HOUR( 6) }, /* Central Daylight */
  546. { &quot;mst&quot;, tZONE, HOUR( 7) }, /* Mountain Standard */
  547. { &quot;mdt&quot;, tDAYZONE, HOUR( 7) }, /* Mountain Daylight */
  548. { &quot;pst&quot;, tZONE, HOUR( 8) }, /* Pacific Standard */
  549. { &quot;pdt&quot;, tDAYZONE, HOUR( 8) }, /* Pacific Daylight */
  550. { &quot;yst&quot;, tZONE, HOUR( 9) }, /* Yukon Standard */
  551. { &quot;ydt&quot;, tDAYZONE, HOUR( 9) }, /* Yukon Daylight */
  552. { &quot;hst&quot;, tZONE, HOUR(10) }, /* Hawaii Standard */
  553. { &quot;hdt&quot;, tDAYZONE, HOUR(10) }, /* Hawaii Daylight */
  554. { &quot;cat&quot;, tZONE, HOUR(10) }, /* Central Alaska */
  555. { &quot;ahst&quot;, tZONE, HOUR(10) }, /* Alaska-Hawaii Standard */
  556. { &quot;nt&quot;, tZONE, HOUR(11) }, /* Nome */
  557. { &quot;idlw&quot;, tZONE, HOUR(12) }, /* International Date Line West */
  558. { &quot;cet&quot;, tZONE, -HOUR( 1) }, /* Central European */
  559. { &quot;cest&quot;, tDAYZONE, -HOUR( 1) }, /* Central European Summer */
  560. { &quot;met&quot;, tZONE, -HOUR( 1) }, /* Middle European */
  561. { &quot;mewt&quot;, tZONE, -HOUR( 1) }, /* Middle European Winter */
  562. { &quot;mest&quot;, tDAYZONE, -HOUR( 1) }, /* Middle European Summer */
  563. { &quot;swt&quot;, tZONE, -HOUR( 1) }, /* Swedish Winter */
  564. { &quot;sst&quot;, tDAYZONE, -HOUR( 1) }, /* Swedish Summer */
  565. { &quot;fwt&quot;, tZONE, -HOUR( 1) }, /* French Winter */
  566. { &quot;fst&quot;, tDAYZONE, -HOUR( 1) }, /* French Summer */
  567. { &quot;eet&quot;, tZONE, -HOUR( 2) }, /* Eastern Europe, USSR Zone 1 */
  568. { &quot;bt&quot;, tZONE, -HOUR( 3) }, /* Baghdad, USSR Zone 2 */
  569. { &quot;it&quot;, tZONE, -HOUR( 7/2) }, /* Iran */
  570. { &quot;zp4&quot;, tZONE, -HOUR( 4) }, /* USSR Zone 3 */
  571. { &quot;zp5&quot;, tZONE, -HOUR( 5) }, /* USSR Zone 4 */
  572. { &quot;ist&quot;, tZONE, -HOUR(11/2) }, /* Indian Standard */
  573. { &quot;zp6&quot;, tZONE, -HOUR( 6) }, /* USSR Zone 5 */
  574. #if 0
  575. /* For completeness. NST is also Newfoundland Stanard, nad SST is
  576. * also Swedish Summer. */
  577. { &quot;nst&quot;, tZONE, -HOUR(13/2) }, /* North Sumatra */
  578. { &quot;sst&quot;, tZONE, -HOUR( 7) }, /* South Sumatra, USSR Zone 6 */
  579. #endif /* 0 */
  580. { &quot;wast&quot;, tZONE, -HOUR( 7) }, /* West Australian Standard */
  581. { &quot;wadt&quot;, tDAYZONE, -HOUR( 7) }, /* West Australian Daylight */
  582. { &quot;jt&quot;, tZONE, -HOUR(15/2) }, /* Java (3pm in Cronusland!) */
  583. { &quot;cct&quot;, tZONE, -HOUR( 8) }, /* China Coast, USSR Zone 7 */
  584. { &quot;jst&quot;, tZONE, -HOUR( 9) }, /* Japan Standard, USSR Zone 8 */
  585. { &quot;jdt&quot;, tDAYZONE, -HOUR( 9) }, /* Japan Daylight */
  586. { &quot;kst&quot;, tZONE, -HOUR( 9) }, /* Korea Standard */
  587. { &quot;kdt&quot;, tDAYZONE, -HOUR( 9) }, /* Korea Daylight */
  588. { &quot;cast&quot;, tZONE, -HOUR(19/2) }, /* Central Australian Standard */
  589. { &quot;cadt&quot;, tDAYZONE, -HOUR(19/2) }, /* Central Australian Daylight */
  590. { &quot;east&quot;, tZONE, -HOUR(10) }, /* Eastern Australian Standard */
  591. { &quot;eadt&quot;, tDAYZONE, -HOUR(10) }, /* Eastern Australian Daylight */
  592. { &quot;gst&quot;, tZONE, -HOUR(10) }, /* Guam Standard, USSR Zone 9 */
  593. { &quot;nzt&quot;, tZONE, -HOUR(12) }, /* New Zealand */
  594. { &quot;nzst&quot;, tZONE, -HOUR(12) }, /* New Zealand Standard */
  595. { &quot;nzdt&quot;, tDAYZONE, -HOUR(12) }, /* New Zealand Daylight */
  596. { &quot;idle&quot;, tZONE, -HOUR(12) }, /* International Date Line East */
  597. /* ADDED BY Marco Nijdam */
  598. { &quot;dst&quot;, tDST, HOUR( 0) }, /* DST on (hour is ignored) */
  599. /* End ADDED */
  600. { NULL }
  601. };
  602. /*
  603. * Military timezone table.
  604. */
  605. static TABLE MilitaryTable[] = {
  606. { &quot;a&quot;, tZONE, -HOUR( 1) },
  607. { &quot;b&quot;, tZONE, -HOUR( 2) },
  608. { &quot;c&quot;, tZONE, -HOUR( 3) },
  609. { &quot;d&quot;, tZONE, -HOUR( 4) },
  610. { &quot;e&quot;, tZONE, -HOUR( 5) },
  611. { &quot;f&quot;, tZONE, -HOUR( 6) },
  612. { &quot;g&quot;, tZONE, -HOUR( 7) },
  613. { &quot;h&quot;, tZONE, -HOUR( 8) },
  614. { &quot;i&quot;, tZONE, -HOUR( 9) },
  615. { &quot;k&quot;, tZONE, -HOUR(10) },
  616. { &quot;l&quot;, tZONE, -HOUR(11) },
  617. { &quot;m&quot;, tZONE, -HOUR(12) },
  618. { &quot;n&quot;, tZONE, HOUR( 1) },
  619. { &quot;o&quot;, tZONE, HOUR( 2) },
  620. { &quot;p&quot;, tZONE, HOUR( 3) },
  621. { &quot;q&quot;, tZONE, HOUR( 4) },
  622. { &quot;r&quot;, tZONE, HOUR( 5) },
  623. { &quot;s&quot;, tZONE, HOUR( 6) },
  624. { &quot;t&quot;, tZONE, HOUR( 7) },
  625. { &quot;u&quot;, tZONE, HOUR( 8) },
  626. { &quot;v&quot;, tZONE, HOUR( 9) },
  627. { &quot;w&quot;, tZONE, HOUR( 10) },
  628. { &quot;x&quot;, tZONE, HOUR( 11) },
  629. { &quot;y&quot;, tZONE, HOUR( 12) },
  630. { &quot;z&quot;, tZONE, HOUR( 0) },
  631. { NULL }
  632. };
  633. /*
  634. * Dump error messages in the bit bucket.
  635. */
  636. static void
  637. TclDateerror(
  638. char *s)
  639. {
  640. }
  641. static time_t
  642. ToSeconds(
  643. time_t Hours,
  644. time_t Minutes,
  645. time_t Seconds,
  646. MERIDIAN Meridian)
  647. {
  648. if (Minutes &lt; 0 || Minutes &gt; 59 || Seconds &lt; 0 || Seconds &gt; 59) {
  649. return -1;
  650. }
  651. switch (Meridian) {
  652. case MER24:
  653. if (Hours &lt; 0 || Hours &gt; 23) {
  654. return -1;
  655. }
  656. return (Hours * 60L + Minutes) * 60L + Seconds;
  657. case MERam:
  658. if (Hours &lt; 1 || Hours &gt; 12) {
  659. return -1;
  660. }
  661. return ((Hours % 12) * 60L + Minutes) * 60L + Seconds;
  662. case MERpm:
  663. if (Hours &lt; 1 || Hours &gt; 12) {
  664. return -1;
  665. }
  666. return (((Hours % 12) + 12) * 60L + Minutes) * 60L + Seconds;
  667. }
  668. return -1; /* Should never be reached */
  669. }
  670. static int
  671. LookupWord(
  672. char *buff)
  673. {
  674. register char *p;
  675. register char *q;
  676. register TABLE *tp;
  677. int i, abbrev;
  678. /*
  679. * Make it lowercase.
  680. */
  681. Tcl_UtfToLower(buff);
  682. if (strcmp(buff, &quot;am&quot;) == 0 || strcmp(buff, &quot;a.m.&quot;) == 0) {
  683. yylval.Meridian = MERam;
  684. return tMERIDIAN;
  685. }
  686. if (strcmp(buff, &quot;pm&quot;) == 0 || strcmp(buff, &quot;p.m.&quot;) == 0) {
  687. yylval.Meridian = MERpm;
  688. return tMERIDIAN;
  689. }
  690. /*
  691. * See if we have an abbreviation for a month.
  692. */
  693. if (strlen(buff) == 3) {
  694. abbrev = 1;
  695. } else if (strlen(buff) == 4 &amp;&amp; buff[3] == '.') {
  696. abbrev = 1;
  697. buff[3] = '\0';
  698. } else {
  699. abbrev = 0;
  700. }
  701. for (tp = MonthDayTable; tp-&gt;name; tp++) {
  702. if (abbrev) {
  703. if (strncmp(buff, tp-&gt;name, 3) == 0) {
  704. yylval.Number = tp-&gt;value;
  705. return tp-&gt;type;
  706. }
  707. } else if (strcmp(buff, tp-&gt;name) == 0) {
  708. yylval.Number = tp-&gt;value;
  709. return tp-&gt;type;
  710. }
  711. }
  712. for (tp = TimezoneTable; tp-&gt;name; tp++) {
  713. if (strcmp(buff, tp-&gt;name) == 0) {
  714. yylval.Number = tp-&gt;value;
  715. return tp-&gt;type;
  716. }
  717. }
  718. for (tp = UnitsTable; tp-&gt;name; tp++) {
  719. if (strcmp(buff, tp-&gt;name) == 0) {
  720. yylval.Number = tp-&gt;value;
  721. return tp-&gt;type;
  722. }
  723. }
  724. /*
  725. * Strip off any plural and try the units table again.
  726. */
  727. i = strlen(buff) - 1;
  728. if (i &gt; 0 &amp;&amp; buff[i] == 's') {
  729. buff[i] = '\0';
  730. for (tp = UnitsTable; tp-&gt;name; tp++) {
  731. if (strcmp(buff, tp-&gt;name) == 0) {
  732. yylval.Number = tp-&gt;value;
  733. return tp-&gt;type;
  734. }
  735. }
  736. }
  737. for (tp = OtherTable; tp-&gt;name; tp++) {
  738. if (strcmp(buff, tp-&gt;name) == 0) {
  739. yylval.Number = tp-&gt;value;
  740. return tp-&gt;type;
  741. }
  742. }
  743. /*
  744. * Military timezones.
  745. */
  746. if (buff[1] == '\0' &amp;&amp; !(*buff &amp; 0x80)
  747. &amp;&amp; isalpha(UCHAR(*buff))) { /* INTL: ISO only */
  748. for (tp = MilitaryTable; tp-&gt;name; tp++) {
  749. if (strcmp(buff, tp-&gt;name) == 0) {
  750. yylval.Number = tp-&gt;value;
  751. return tp-&gt;type;
  752. }
  753. }
  754. }
  755. /*
  756. * Drop out any periods and try the timezone table again.
  757. */
  758. for (i = 0, p = q = buff; *q; q++) {
  759. if (*q != '.') {
  760. *p++ = *q;
  761. } else {
  762. i++;
  763. }
  764. }
  765. *p = '\0';
  766. if (i) {
  767. for (tp = TimezoneTable; tp-&gt;name; tp++) {
  768. if (strcmp(buff, tp-&gt;name) == 0) {
  769. yylval.Number = tp-&gt;value;
  770. return tp-&gt;type;
  771. }
  772. }
  773. }
  774. return tID;
  775. }
  776. static int
  777. TclDatelex(
  778. void *info)
  779. {
  780. register char c;
  781. register char *p;
  782. char buff[20];
  783. int Count;
  784. for ( ; ; ) {
  785. while (isspace(UCHAR(*yyInput))) {
  786. yyInput++;
  787. }
  788. if (isdigit(UCHAR(c = *yyInput))) { /* INTL: digit */
  789. /*
  790. * Convert the string into a number; count the number of digits.
  791. */
  792. Count = 0;
  793. for (yylval.Number = 0;
  794. isdigit(UCHAR(c = *yyInput++)); ) { /* INTL: digit */
  795. yylval.Number = 10 * yylval.Number + c - '0';
  796. Count++;
  797. }
  798. yyInput--;
  799. yyDigitCount = Count;
  800. /*
  801. * A number with 6 or more digits is considered an ISO 8601 base.
  802. */
  803. if (Count &gt;= 6) {
  804. return tISOBASE;
  805. } else {
  806. return tUNUMBER;
  807. }
  808. }
  809. if (!(c &amp; 0x80) &amp;&amp; isalpha(UCHAR(c))) { /* INTL: ISO only. */
  810. for (p = buff; isalpha(UCHAR(c = *yyInput++)) /* INTL: ISO only. */
  811. || c == '.'; ) {
  812. if (p &lt; &amp;buff[sizeof buff - 1]) {
  813. *p++ = c;
  814. }
  815. }
  816. *p = '\0';
  817. yyInput--;
  818. return LookupWord(buff);
  819. }
  820. if (c != '(') {
  821. return *yyInput++;
  822. }
  823. Count = 0;
  824. do {
  825. c = *yyInput++;
  826. if (c == '\0') {
  827. return c;
  828. } else if (c == '(') {
  829. Count++;
  830. } else if (c == ')') {
  831. Count--;
  832. }
  833. } while (Count &gt; 0);
  834. }
  835. }
  836. int
  837. TclClockOldscanObjCmd(
  838. ClientData clientData, /* Unused */
  839. Tcl_Interp *interp, /* Tcl interpreter */
  840. int objc, /* Count of paraneters */
  841. Tcl_Obj *CONST *objv) /* Parameters */
  842. {
  843. Tcl_Obj *result, *resultElement;
  844. int yr, mo, da;
  845. DateInfo dateInfo;
  846. void *info = (void *) &amp;dateInfo;
  847. if (objc != 5) {
  848. Tcl_WrongNumArgs(interp, 1, objv,
  849. &quot;stringToParse baseYear baseMonth baseDay&quot; );
  850. return TCL_ERROR;
  851. }
  852. yyInput = Tcl_GetString( objv[1] );
  853. yyHaveDate = 0;
  854. if (Tcl_GetIntFromObj(interp, objv[2], &amp;yr) != TCL_OK
  855. || Tcl_GetIntFromObj(interp, objv[3], &amp;mo) != TCL_OK
  856. || Tcl_GetIntFromObj(interp, objv[4], &amp;da) != TCL_OK) {
  857. return TCL_ERROR;
  858. }
  859. yyYear = yr; yyMonth = mo; yyDay = da;
  860. yyHaveTime = 0;
  861. yyHour = 0; yyMinutes = 0; yySeconds = 0; yyMeridian = MER24;
  862. yyHaveZone = 0;
  863. yyTimezone = 0; yyDSTmode = DSTmaybe;
  864. yyHaveOrdinalMonth = 0;
  865. yyMonthOrdinal = 0;
  866. yyHaveDay = 0;
  867. yyDayOrdinal = 0; yyDayNumber = 0;
  868. yyHaveRel = 0;
  869. yyRelMonth = 0; yyRelDay = 0; yyRelSeconds = 0; yyRelPointer = NULL;
  870. if (yyparse(info)) {
  871. Tcl_SetObjResult(interp, Tcl_NewStringObj(&quot;syntax error&quot;, -1));
  872. return TCL_ERROR;
  873. }
  874. if (yyHaveDate &gt; 1) {
  875. Tcl_SetObjResult(interp,
  876. Tcl_NewStringObj(&quot;more than one date in string&quot;, -1));
  877. return TCL_ERROR;
  878. }
  879. if (yyHaveTime &gt; 1) {
  880. Tcl_SetObjResult(interp,
  881. Tcl_NewStringObj(&quot;more than one time of day in string&quot;, -1));
  882. return TCL_ERROR;
  883. }
  884. if (yyHaveZone &gt; 1) {
  885. Tcl_SetObjResult(interp,
  886. Tcl_NewStringObj(&quot;more than one time zone in string&quot;, -1));
  887. return TCL_ERROR;
  888. }
  889. if (yyHaveDay &gt; 1) {
  890. Tcl_SetObjResult(interp,
  891. Tcl_NewStringObj(&quot;more than one weekday in string&quot;, -1));
  892. return TCL_ERROR;
  893. }
  894. if (yyHaveOrdinalMonth &gt; 1) {
  895. Tcl_SetObjResult(interp,
  896. Tcl_NewStringObj(&quot;more than one ordinal month in string&quot;, -1));
  897. return TCL_ERROR;
  898. }
  899. result = Tcl_NewObj();
  900. resultElement = Tcl_NewObj();
  901. if (yyHaveDate) {
  902. Tcl_ListObjAppendElement(interp, resultElement,
  903. Tcl_NewIntObj((int) yyYear));
  904. Tcl_ListObjAppendElement(interp, resultElement,
  905. Tcl_NewIntObj((int) yyMonth));
  906. Tcl_ListObjAppendElement(interp, resultElement,
  907. Tcl_NewIntObj((int) yyDay));
  908. }
  909. Tcl_ListObjAppendElement(interp, result, resultElement);
  910. if (yyHaveTime) {
  911. Tcl_ListObjAppendElement(interp, result, Tcl_NewIntObj((int)
  912. ToSeconds(yyHour, yyMinutes, yySeconds, yyMeridian)));
  913. } else {
  914. Tcl_ListObjAppendElement(interp, result, Tcl_NewObj());
  915. }
  916. resultElement = Tcl_NewObj();
  917. if (yyHaveZone) {
  918. Tcl_ListObjAppendElement(interp, resultElement,
  919. Tcl_NewIntObj((int) -yyTimezone));
  920. Tcl_ListObjAppendElement(interp, resultElement,
  921. Tcl_NewIntObj(1 - yyDSTmode));
  922. }
  923. Tcl_ListObjAppendElement(interp, result, resultElement);
  924. resultElement = Tcl_NewObj();
  925. if (yyHaveRel) {
  926. Tcl_ListObjAppendElement(interp, resultElement,
  927. Tcl_NewIntObj((int) yyRelMonth));
  928. Tcl_ListObjAppendElement(interp, resultElement,
  929. Tcl_NewIntObj((int) yyRelDay));
  930. Tcl_ListObjAppendElement(interp, resultElement,
  931. Tcl_NewIntObj((int) yyRelSeconds));
  932. }
  933. Tcl_ListObjAppendElement(interp, result, resultElement);
  934. resultElement = Tcl_NewObj();
  935. if (yyHaveDay &amp;&amp; !yyHaveDate) {
  936. Tcl_ListObjAppendElement(interp, resultElement,
  937. Tcl_NewIntObj((int) yyDayOrdinal));
  938. Tcl_ListObjAppendElement(interp, resultElement,
  939. Tcl_NewIntObj((int) yyDayNumber));
  940. }
  941. Tcl_ListObjAppendElement(interp, result, resultElement);
  942. resultElement = Tcl_NewObj();
  943. if (yyHaveOrdinalMonth) {
  944. Tcl_ListObjAppendElement(interp, resultElement,
  945. Tcl_NewIntObj((int) yyMonthOrdinal));
  946. Tcl_ListObjAppendElement(interp, resultElement,
  947. Tcl_NewIntObj((int) yyMonth));
  948. }
  949. Tcl_ListObjAppendElement(interp, result, resultElement);
  950. Tcl_SetObjResult(interp, result);
  951. return TCL_OK;
  952. }
  953. /*
  954. * Local Variables:
  955. * mode: c
  956. * c-basic-offset: 4
  957. * fill-column: 78
  958. * End:
  959. */
  960. </pre>
  961. <hr />
  962. </body></html>