home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / cvs-1.8.7-src.tgz / tar.out / fsf / cvs / lib / getdate.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  41KB  |  1,507 lines

  1. #ifndef lint
  2. static char yysccsid[] = "@(#)yaccpar    1.9 (Berkeley) 02/21/93";
  3. #endif
  4. #define YYBYACC 1
  5. #define YYMAJOR 1
  6. #define YYMINOR 9
  7. #define yyclearin (yychar=(-1))
  8. #define yyerrok (yyerrflag=0)
  9. #define YYRECOVERING (yyerrflag!=0)
  10. #define YYPREFIX "yy"
  11. #line 2 "../../work/ccvs/lib/getdate.y"
  12. /*
  13. **  Originally written by Steven M. Bellovin <smb@research.att.com> while
  14. **  at the University of North Carolina at Chapel Hill.  Later tweaked by
  15. **  a couple of people on Usenet.  Completely overhauled by Rich $alz
  16. **  <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
  17. **  send any email to Rich.
  18. **
  19. **  This grammar has 10 shift/reduce conflicts.
  20. **
  21. **  This code is in the public domain and has no copyright.
  22. */
  23. /* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */
  24. /* SUPPRESS 288 on yyerrlab *//* Label unused */
  25.  
  26. #ifdef HAVE_CONFIG_H
  27. #if defined (emacs) || defined (CONFIG_BROKETS)
  28. #include <config.h>
  29. #else
  30. #include "config.h"
  31. #endif
  32. #endif
  33.  
  34. /* Since the code of getdate.y is not included in the Emacs executable
  35.    itself, there is no need to #define static in this file.  Even if
  36.    the code were included in the Emacs executable, it probably
  37.    wouldn't do any harm to #undef it here; this will only cause
  38.    problems if we try to write to a static variable, which I don't
  39.    think this code needs to do.  */
  40. #ifdef emacs
  41. #undef static
  42. #endif
  43.  
  44. #include <stdio.h>
  45. #include <ctype.h>
  46.  
  47. /* The code at the top of get_date which figures out the offset of the
  48.    current time zone checks various CPP symbols to see if special
  49.    tricks are need, but defaults to using the gettimeofday system call.
  50.    Include <sys/time.h> if that will be used.  */
  51.  
  52. #if    defined(vms)
  53.  
  54. #include <types.h>
  55. #include <time.h>
  56.  
  57. #else
  58.  
  59. #include <sys/types.h>
  60.  
  61. #ifdef TIME_WITH_SYS_TIME
  62. #include <sys/time.h>
  63. #include <time.h>
  64. #else
  65. #ifdef HAVE_SYS_TIME_H
  66. #include <sys/time.h>
  67. #else
  68. #include <time.h>
  69. #endif
  70. #endif
  71.  
  72. #ifdef timezone
  73. #undef timezone /* needed for sgi */
  74. #endif
  75.  
  76. #if defined(HAVE_SYS_TIMEB_H)
  77. #include <sys/timeb.h>
  78. #else
  79. /*
  80. ** We use the obsolete `struct timeb' as part of our interface!
  81. ** Since the system doesn't have it, we define it here;
  82. ** our callers must do likewise.
  83. */
  84. struct timeb {
  85.     time_t        time;        /* Seconds since the epoch    */
  86.     unsigned short    millitm;    /* Field not used        */
  87.     short        timezone;    /* Minutes west of GMT        */
  88.     short        dstflag;    /* Field not used        */
  89. };
  90. #endif /* defined(HAVE_SYS_TIMEB_H) */
  91.  
  92. #endif    /* defined(vms) */
  93.  
  94. #if defined (STDC_HEADERS) || defined (USG)
  95. #include <string.h>
  96. #endif
  97.  
  98. /* Some old versions of bison generate parsers that use bcopy.
  99.    That loses on systems that don't provide the function, so we have
  100.    to redefine it here.  */
  101. #if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
  102. #define bcopy(from, to, len) memcpy ((to), (from), (len))
  103. #endif
  104.  
  105. #if defined (STDC_HEADERS)
  106. #include <stdlib.h>
  107. #endif
  108.  
  109. /* NOTES on rebuilding getdate.c (particularly for inclusion in CVS
  110.    releases):
  111.  
  112.    We don't want to mess with all the portability hassles of alloca.
  113.    In particular, most (all?) versions of bison will use alloca in
  114.    their parser.  If bison works on your system (e.g. it should work
  115.    with gcc), then go ahead and use it, but the more general solution
  116.    is to use byacc instead of bison, which should generate a portable
  117.    parser.  I played with adding "#define alloca dont_use_alloca", to
  118.    give an error if the parser generator uses alloca (and thus detect
  119.    unportable getdate.c's), but that seems to cause as many problems
  120.    as it solves.  */
  121.  
  122. extern struct tm    *gmtime();
  123. extern struct tm    *localtime();
  124.  
  125. #define yyparse getdate_yyparse
  126. #define yylex getdate_yylex
  127. #define yyerror getdate_yyerror
  128.  
  129. #if    !defined(lint) && !defined(SABER)
  130. static char RCS[] = "$CVSid: @(#)getdate.y 1.11 94/09/21 $";
  131. #endif    /* !defined(lint) && !defined(SABER) */
  132.  
  133. static int yylex ();
  134. static int yyerror ();
  135.  
  136. #define EPOCH        1970
  137. #define HOUR(x)        ((time_t)(x) * 60)
  138. #define SECSPERDAY    (24L * 60L * 60L)
  139.  
  140.  
  141. /*
  142. **  An entry in the lexical lookup table.
  143. */
  144. typedef struct _TABLE {
  145.     char    *name;
  146.     int        type;
  147.     time_t    value;
  148. } TABLE;
  149.  
  150.  
  151. /*
  152. **  Daylight-savings mode:  on, off, or not yet known.
  153. */
  154. typedef enum _DSTMODE {
  155.     DSTon, DSToff, DSTmaybe
  156. } DSTMODE;
  157.  
  158. /*
  159. **  Meridian:  am, pm, or 24-hour style.
  160. */
  161. typedef enum _MERIDIAN {
  162.     MERam, MERpm, MER24
  163. } MERIDIAN;
  164.  
  165.  
  166. /*
  167. **  Global variables.  We could get rid of most of these by using a good
  168. **  union as the yacc stack.  (This routine was originally written before
  169. **  yacc had the %union construct.)  Maybe someday; right now we only use
  170. **  the %union very rarely.
  171. */
  172. static char    *yyInput;
  173. static DSTMODE    yyDSTmode;
  174. static time_t    yyDayOrdinal;
  175. static time_t    yyDayNumber;
  176. static int    yyHaveDate;
  177. static int    yyHaveDay;
  178. static int    yyHaveRel;
  179. static int    yyHaveTime;
  180. static int    yyHaveZone;
  181. static time_t    yyTimezone;
  182. static time_t    yyDay;
  183. static time_t    yyHour;
  184. static time_t    yyMinutes;
  185. static time_t    yyMonth;
  186. static time_t    yySeconds;
  187. static time_t    yyYear;
  188. static MERIDIAN    yyMeridian;
  189. static time_t    yyRelMonth;
  190. static time_t    yyRelSeconds;
  191.  
  192. #line 184 "../../work/ccvs/lib/getdate.y"
  193. typedef union {
  194.     time_t        Number;
  195.     enum _MERIDIAN    Meridian;
  196. } YYSTYPE;
  197. #line 198 "y.tab.c"
  198. #define tAGO 257
  199. #define tDAY 258
  200. #define tDAYZONE 259
  201. #define tID 260
  202. #define tMERIDIAN 261
  203. #define tMINUTE_UNIT 262
  204. #define tMONTH 263
  205. #define tMONTH_UNIT 264
  206. #define tSEC_UNIT 265
  207. #define tSNUMBER 266
  208. #define tUNUMBER 267
  209. #define tZONE 268
  210. #define tDST 269
  211. #define YYERRCODE 256
  212. short yylhs[] = {                                        -1,
  213.     0,    0,    2,    2,    2,    2,    2,    2,    3,    3,
  214.     3,    3,    3,    4,    4,    4,    6,    6,    6,    5,
  215.     5,    5,    5,    5,    5,    5,    5,    7,    7,    9,
  216.     9,    9,    9,    9,    9,    9,    9,    9,    8,    1,
  217.     1,
  218. };
  219. short yylen[] = {                                         2,
  220.     0,    2,    1,    1,    1,    1,    1,    1,    2,    4,
  221.     4,    6,    6,    1,    1,    2,    1,    2,    2,    3,
  222.     5,    3,    3,    2,    4,    2,    3,    2,    1,    2,
  223.     2,    1,    2,    2,    1,    2,    2,    1,    1,    0,
  224.     1,
  225. };
  226. short yydefred[] = {                                      1,
  227.     0,    0,   15,   32,    0,   38,   35,    0,    0,    0,
  228.     2,    3,    4,    5,    6,    7,    8,    0,   18,    0,
  229.    31,   36,   33,   19,    9,   30,    0,   37,   34,    0,
  230.     0,    0,   16,   28,    0,   23,   27,   22,    0,    0,
  231.    25,   41,   11,    0,   10,    0,    0,   21,   13,   12,
  232. };
  233. short yydgoto[] = {                                       1,
  234.    45,   11,   12,   13,   14,   15,   16,   17,   18,
  235. };
  236. short yysindex[] = {                                      0,
  237.  -249,  -38,    0,    0, -260,    0,    0, -240,  -47, -248,
  238.     0,    0,    0,    0,    0,    0,    0, -237,    0,  -18,
  239.     0,    0,    0,    0,    0,    0, -262,    0,    0, -239,
  240.  -238, -236,    0,    0, -235,    0,    0,    0,  -56,  -19,
  241.     0,    0,    0, -234,    0, -232, -258,    0,    0,    0,
  242. };
  243. short yyrindex[] = {                                      0,
  244.     0,    1,    0,    0,    0,    0,    0,    0,   69,   12,
  245.     0,    0,    0,    0,    0,    0,    0,   23,    0,   34,
  246.     0,    0,    0,    0,    0,    0,   67,    0,    0,    0,
  247.     0,    0,    0,    0,    0,    0,    0,    0,   56,   45,
  248.     0,    0,    0,    0,    0,    0,   56,    0,    0,    0,
  249. };
  250. short yygindex[] = {                                      0,
  251.   -17,    0,    0,    0,    0,    0,    0,    0,    0,
  252. };
  253. #define YYTABLESIZE 337
  254. short yytable[] = {                                      32,
  255.    17,   44,   42,   36,   37,   19,   20,   49,    2,    3,
  256.    31,   14,    4,    5,    6,    7,    8,    9,   10,   34,
  257.    33,   21,   29,   22,   23,   35,   38,   46,   39,   50,
  258.    40,   41,   47,   24,   48,    0,    0,    0,    0,    0,
  259.     0,    0,    0,    0,   20,    0,    0,    0,    0,    0,
  260.     0,    0,    0,    0,    0,   40,    0,    0,    0,    0,
  261.     0,    0,    0,    0,    0,    0,   26,    0,   39,    0,
  262.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  263.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  264.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  265.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  266.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  267.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  268.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  269.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  270.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  271.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  272.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  273.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  274.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  275.     0,    0,    0,    0,   42,    0,    0,    0,    0,   43,
  276.    24,    0,    0,   25,   26,   27,   28,   29,   30,    0,
  277.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  278.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  279.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  280.     0,    0,    0,    0,    0,    0,    0,    0,   17,   17,
  281.     0,    0,   17,   17,   17,   17,   17,   17,   17,   14,
  282.    14,    0,    0,   14,   14,   14,   14,   14,   14,   14,
  283.    29,   29,    0,    0,   29,   29,   29,   29,   29,   29,
  284.    29,   24,   24,    0,    0,   24,   24,   24,   24,   24,
  285.    24,   24,   20,   20,    0,    0,   20,   20,   20,   20,
  286.    20,   20,   20,   40,   40,    0,    0,   40,   40,   40,
  287.    40,    0,   40,   40,   26,   26,    0,   39,   26,   26,
  288.    26,   26,    0,    0,   26,   39,   39,
  289. };
  290. short yycheck[] = {                                      47,
  291.     0,   58,  261,  266,  267,   44,  267,  266,  258,  259,
  292.    58,    0,  262,  263,  264,  265,  266,  267,  268,  257,
  293.   269,  262,    0,  264,  265,   44,  266,   47,  267,   47,
  294.   267,  267,  267,    0,  267,   -1,   -1,   -1,   -1,   -1,
  295.    -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,
  296.    -1,   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,   -1,
  297.    -1,   -1,   -1,   -1,   -1,   -1,    0,   -1,    0,   -1,
  298.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  299.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  300.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  301.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  302.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  303.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  304.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  305.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  306.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  307.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  308.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  309.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  310.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  311.    -1,   -1,   -1,   -1,  261,   -1,   -1,   -1,   -1,  266,
  312.   258,   -1,   -1,  261,  262,  263,  264,  265,  266,   -1,
  313.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  314.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  315.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  316.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  258,  259,
  317.    -1,   -1,  262,  263,  264,  265,  266,  267,  268,  258,
  318.   259,   -1,   -1,  262,  263,  264,  265,  266,  267,  268,
  319.   258,  259,   -1,   -1,  262,  263,  264,  265,  266,  267,
  320.   268,  258,  259,   -1,   -1,  262,  263,  264,  265,  266,
  321.   267,  268,  258,  259,   -1,   -1,  262,  263,  264,  265,
  322.   266,  267,  268,  258,  259,   -1,   -1,  262,  263,  264,
  323.   265,   -1,  267,  268,  258,  259,   -1,  259,  262,  263,
  324.   264,  265,   -1,   -1,  268,  267,  268,
  325. };
  326. #define YYFINAL 1
  327. #ifndef YYDEBUG
  328. #define YYDEBUG 0
  329. #endif
  330. #define YYMAXTOKEN 269
  331. #if YYDEBUG
  332. char *yyname[] = {
  333. "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  334. 0,0,0,0,0,0,0,0,0,0,"','",0,0,"'/'",0,0,0,0,0,0,0,0,0,0,"':'",0,0,0,0,0,0,0,0,0,
  335. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  336. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  337. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  338. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  339. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"tAGO","tDAY",
  340. "tDAYZONE","tID","tMERIDIAN","tMINUTE_UNIT","tMONTH","tMONTH_UNIT","tSEC_UNIT",
  341. "tSNUMBER","tUNUMBER","tZONE","tDST",
  342. };
  343. char *yyrule[] = {
  344. "$accept : spec",
  345. "spec :",
  346. "spec : spec item",
  347. "item : time",
  348. "item : zone",
  349. "item : date",
  350. "item : day",
  351. "item : rel",
  352. "item : number",
  353. "time : tUNUMBER tMERIDIAN",
  354. "time : tUNUMBER ':' tUNUMBER o_merid",
  355. "time : tUNUMBER ':' tUNUMBER tSNUMBER",
  356. "time : tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid",
  357. "time : tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER",
  358. "zone : tZONE",
  359. "zone : tDAYZONE",
  360. "zone : tZONE tDST",
  361. "day : tDAY",
  362. "day : tDAY ','",
  363. "day : tUNUMBER tDAY",
  364. "date : tUNUMBER '/' tUNUMBER",
  365. "date : tUNUMBER '/' tUNUMBER '/' tUNUMBER",
  366. "date : tUNUMBER tSNUMBER tSNUMBER",
  367. "date : tUNUMBER tMONTH tSNUMBER",
  368. "date : tMONTH tUNUMBER",
  369. "date : tMONTH tUNUMBER ',' tUNUMBER",
  370. "date : tUNUMBER tMONTH",
  371. "date : tUNUMBER tMONTH tUNUMBER",
  372. "rel : relunit tAGO",
  373. "rel : relunit",
  374. "relunit : tUNUMBER tMINUTE_UNIT",
  375. "relunit : tSNUMBER tMINUTE_UNIT",
  376. "relunit : tMINUTE_UNIT",
  377. "relunit : tSNUMBER tSEC_UNIT",
  378. "relunit : tUNUMBER tSEC_UNIT",
  379. "relunit : tSEC_UNIT",
  380. "relunit : tSNUMBER tMONTH_UNIT",
  381. "relunit : tUNUMBER tMONTH_UNIT",
  382. "relunit : tMONTH_UNIT",
  383. "number : tUNUMBER",
  384. "o_merid :",
  385. "o_merid : tMERIDIAN",
  386. };
  387. #endif
  388. #ifdef YYSTACKSIZE
  389. #undef YYMAXDEPTH
  390. #define YYMAXDEPTH YYSTACKSIZE
  391. #else
  392. #ifdef YYMAXDEPTH
  393. #define YYSTACKSIZE YYMAXDEPTH
  394. #else
  395. #define YYSTACKSIZE 500
  396. #define YYMAXDEPTH 500
  397. #endif
  398. #endif
  399. int yydebug;
  400. int yynerrs;
  401. int yyerrflag;
  402. int yychar;
  403. short *yyssp;
  404. YYSTYPE *yyvsp;
  405. YYSTYPE yyval;
  406. YYSTYPE yylval;
  407. short yyss[YYSTACKSIZE];
  408. YYSTYPE yyvs[YYSTACKSIZE];
  409. #define yystacksize YYSTACKSIZE
  410. #line 397 "../../work/ccvs/lib/getdate.y"
  411.  
  412. /* Month and day table. */
  413. static TABLE const 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. /* Time units table. */
  442. static TABLE const UnitsTable[] = {
  443.     { "year",        tMONTH_UNIT,    12 },
  444.     { "month",        tMONTH_UNIT,    1 },
  445.     { "fortnight",    tMINUTE_UNIT,    14 * 24 * 60 },
  446.     { "week",        tMINUTE_UNIT,    7 * 24 * 60 },
  447.     { "day",        tMINUTE_UNIT,    1 * 24 * 60 },
  448.     { "hour",        tMINUTE_UNIT,    60 },
  449.     { "minute",        tMINUTE_UNIT,    1 },
  450.     { "min",        tMINUTE_UNIT,    1 },
  451.     { "second",        tSEC_UNIT,    1 },
  452.     { "sec",        tSEC_UNIT,    1 },
  453.     { NULL }
  454. };
  455.  
  456. /* Assorted relative-time words. */
  457. static TABLE const OtherTable[] = {
  458.     { "tomorrow",    tMINUTE_UNIT,    1 * 24 * 60 },
  459.     { "yesterday",    tMINUTE_UNIT,    -1 * 24 * 60 },
  460.     { "today",        tMINUTE_UNIT,    0 },
  461.     { "now",        tMINUTE_UNIT,    0 },
  462.     { "last",        tUNUMBER,    -1 },
  463.     { "this",        tMINUTE_UNIT,    0 },
  464.     { "next",        tUNUMBER,    2 },
  465.     { "first",        tUNUMBER,    1 },
  466. /*  { "second",        tUNUMBER,    2 }, */
  467.     { "third",        tUNUMBER,    3 },
  468.     { "fourth",        tUNUMBER,    4 },
  469.     { "fifth",        tUNUMBER,    5 },
  470.     { "sixth",        tUNUMBER,    6 },
  471.     { "seventh",    tUNUMBER,    7 },
  472.     { "eighth",        tUNUMBER,    8 },
  473.     { "ninth",        tUNUMBER,    9 },
  474.     { "tenth",        tUNUMBER,    10 },
  475.     { "eleventh",    tUNUMBER,    11 },
  476.     { "twelfth",    tUNUMBER,    12 },
  477.     { "ago",        tAGO,    1 },
  478.     { NULL }
  479. };
  480.  
  481. /* The timezone table. */
  482. /* Some of these are commented out because a time_t can't store a float. */
  483. static TABLE const TimezoneTable[] = {
  484.     { "gmt",    tZONE,     HOUR( 0) },    /* Greenwich Mean */
  485.     { "ut",    tZONE,     HOUR( 0) },    /* Universal (Coordinated) */
  486.     { "utc",    tZONE,     HOUR( 0) },
  487.     { "wet",    tZONE,     HOUR( 0) },    /* Western European */
  488.     { "bst",    tDAYZONE,  HOUR( 0) },    /* British Summer */
  489.     { "wat",    tZONE,     HOUR( 1) },    /* West Africa */
  490.     { "at",    tZONE,     HOUR( 2) },    /* Azores */
  491. #if    0
  492.     /* For completeness.  BST is also British Summer, and GST is
  493.      * also Guam Standard. */
  494.     { "bst",    tZONE,     HOUR( 3) },    /* Brazil Standard */
  495.     { "gst",    tZONE,     HOUR( 3) },    /* Greenland Standard */
  496. #endif
  497. #if 0
  498.     { "nft",    tZONE,     HOUR(3.5) },    /* Newfoundland */
  499.     { "nst",    tZONE,     HOUR(3.5) },    /* Newfoundland Standard */
  500.     { "ndt",    tDAYZONE,  HOUR(3.5) },    /* Newfoundland Daylight */
  501. #endif
  502.     { "ast",    tZONE,     HOUR( 4) },    /* Atlantic Standard */
  503.     { "adt",    tDAYZONE,  HOUR( 4) },    /* Atlantic Daylight */
  504.     { "est",    tZONE,     HOUR( 5) },    /* Eastern Standard */
  505.     { "edt",    tDAYZONE,  HOUR( 5) },    /* Eastern Daylight */
  506.     { "cst",    tZONE,     HOUR( 6) },    /* Central Standard */
  507.     { "cdt",    tDAYZONE,  HOUR( 6) },    /* Central Daylight */
  508.     { "mst",    tZONE,     HOUR( 7) },    /* Mountain Standard */
  509.     { "mdt",    tDAYZONE,  HOUR( 7) },    /* Mountain Daylight */
  510.     { "pst",    tZONE,     HOUR( 8) },    /* Pacific Standard */
  511.     { "pdt",    tDAYZONE,  HOUR( 8) },    /* Pacific Daylight */
  512.     { "yst",    tZONE,     HOUR( 9) },    /* Yukon Standard */
  513.     { "ydt",    tDAYZONE,  HOUR( 9) },    /* Yukon Daylight */
  514.     { "hst",    tZONE,     HOUR(10) },    /* Hawaii Standard */
  515.     { "hdt",    tDAYZONE,  HOUR(10) },    /* Hawaii Daylight */
  516.     { "cat",    tZONE,     HOUR(10) },    /* Central Alaska */
  517.     { "ahst",    tZONE,     HOUR(10) },    /* Alaska-Hawaii Standard */
  518.     { "nt",    tZONE,     HOUR(11) },    /* Nome */
  519.     { "idlw",    tZONE,     HOUR(12) },    /* International Date Line West */
  520.     { "cet",    tZONE,     -HOUR(1) },    /* Central European */
  521.     { "met",    tZONE,     -HOUR(1) },    /* Middle European */
  522.     { "mewt",    tZONE,     -HOUR(1) },    /* Middle European Winter */
  523.     { "mest",    tDAYZONE,  -HOUR(1) },    /* Middle European Summer */
  524.     { "swt",    tZONE,     -HOUR(1) },    /* Swedish Winter */
  525.     { "sst",    tDAYZONE,  -HOUR(1) },    /* Swedish Summer */
  526.     { "fwt",    tZONE,     -HOUR(1) },    /* French Winter */
  527.     { "fst",    tDAYZONE,  -HOUR(1) },    /* French Summer */
  528.     { "eet",    tZONE,     -HOUR(2) },    /* Eastern Europe, USSR Zone 1 */
  529.     { "bt",    tZONE,     -HOUR(3) },    /* Baghdad, USSR Zone 2 */
  530. #if 0
  531.     { "it",    tZONE,     -HOUR(3.5) },/* Iran */
  532. #endif
  533.     { "zp4",    tZONE,     -HOUR(4) },    /* USSR Zone 3 */
  534.     { "zp5",    tZONE,     -HOUR(5) },    /* USSR Zone 4 */
  535. #if 0
  536.     { "ist",    tZONE,     -HOUR(5.5) },/* Indian Standard */
  537. #endif
  538.     { "zp6",    tZONE,     -HOUR(6) },    /* USSR Zone 5 */
  539. #if    0
  540.     /* For completeness.  NST is also Newfoundland Stanard, and SST is
  541.      * also Swedish Summer. */
  542.     { "nst",    tZONE,     -HOUR(6.5) },/* North Sumatra */
  543.     { "sst",    tZONE,     -HOUR(7) },    /* South Sumatra, USSR Zone 6 */
  544. #endif    /* 0 */
  545.     { "wast",    tZONE,     -HOUR(7) },    /* West Australian Standard */
  546.     { "wadt",    tDAYZONE,  -HOUR(7) },    /* West Australian Daylight */
  547. #if 0
  548.     { "jt",    tZONE,     -HOUR(7.5) },/* Java (3pm in Cronusland!) */
  549. #endif
  550.     { "cct",    tZONE,     -HOUR(8) },    /* China Coast, USSR Zone 7 */
  551.     { "jst",    tZONE,     -HOUR(9) },    /* Japan Standard, USSR Zone 8 */
  552. #if 0
  553.     { "cast",    tZONE,     -HOUR(9.5) },/* Central Australian Standard */
  554.     { "cadt",    tDAYZONE,  -HOUR(9.5) },/* Central Australian Daylight */
  555. #endif
  556.     { "east",    tZONE,     -HOUR(10) },    /* Eastern Australian Standard */
  557.     { "eadt",    tDAYZONE,  -HOUR(10) },    /* Eastern Australian Daylight */
  558.     { "gst",    tZONE,     -HOUR(10) },    /* Guam Standard, USSR Zone 9 */
  559.     { "nzt",    tZONE,     -HOUR(12) },    /* New Zealand */
  560.     { "nzst",    tZONE,     -HOUR(12) },    /* New Zealand Standard */
  561.     { "nzdt",    tDAYZONE,  -HOUR(12) },    /* New Zealand Daylight */
  562.     { "idle",    tZONE,     -HOUR(12) },    /* International Date Line East */
  563.     {  NULL  }
  564. };
  565.  
  566. /* Military timezone table. */
  567. static TABLE const MilitaryTable[] = {
  568.     { "a",    tZONE,    HOUR(  1) },
  569.     { "b",    tZONE,    HOUR(  2) },
  570.     { "c",    tZONE,    HOUR(  3) },
  571.     { "d",    tZONE,    HOUR(  4) },
  572.     { "e",    tZONE,    HOUR(  5) },
  573.     { "f",    tZONE,    HOUR(  6) },
  574.     { "g",    tZONE,    HOUR(  7) },
  575.     { "h",    tZONE,    HOUR(  8) },
  576.     { "i",    tZONE,    HOUR(  9) },
  577.     { "k",    tZONE,    HOUR( 10) },
  578.     { "l",    tZONE,    HOUR( 11) },
  579.     { "m",    tZONE,    HOUR( 12) },
  580.     { "n",    tZONE,    HOUR(- 1) },
  581.     { "o",    tZONE,    HOUR(- 2) },
  582.     { "p",    tZONE,    HOUR(- 3) },
  583.     { "q",    tZONE,    HOUR(- 4) },
  584.     { "r",    tZONE,    HOUR(- 5) },
  585.     { "s",    tZONE,    HOUR(- 6) },
  586.     { "t",    tZONE,    HOUR(- 7) },
  587.     { "u",    tZONE,    HOUR(- 8) },
  588.     { "v",    tZONE,    HOUR(- 9) },
  589.     { "w",    tZONE,    HOUR(-10) },
  590.     { "x",    tZONE,    HOUR(-11) },
  591.     { "y",    tZONE,    HOUR(-12) },
  592.     { "z",    tZONE,    HOUR(  0) },
  593.     { NULL }
  594. };
  595.  
  596.  
  597.  
  598.  
  599. /* ARGSUSED */
  600. static int
  601. yyerror(s)
  602.     char    *s;
  603. {
  604.   return 0;
  605. }
  606.  
  607.  
  608. static time_t
  609. ToSeconds(Hours, Minutes, Seconds, Meridian)
  610.     time_t    Hours;
  611.     time_t    Minutes;
  612.     time_t    Seconds;
  613.     MERIDIAN    Meridian;
  614. {
  615.     if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59)
  616.     return -1;
  617.     switch (Meridian) {
  618.     case MER24:
  619.     if (Hours < 0 || Hours > 23)
  620.         return -1;
  621.     return (Hours * 60L + Minutes) * 60L + Seconds;
  622.     case MERam:
  623.     if (Hours < 1 || Hours > 12)
  624.         return -1;
  625.     return (Hours * 60L + Minutes) * 60L + Seconds;
  626.     case MERpm:
  627.     if (Hours < 1 || Hours > 12)
  628.         return -1;
  629.     return ((Hours + 12) * 60L + Minutes) * 60L + Seconds;
  630.     default:
  631.     abort ();
  632.     }
  633.     /* NOTREACHED */
  634. }
  635.  
  636.  
  637. static time_t
  638. Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode)
  639.     time_t    Month;
  640.     time_t    Day;
  641.     time_t    Year;
  642.     time_t    Hours;
  643.     time_t    Minutes;
  644.     time_t    Seconds;
  645.     MERIDIAN    Meridian;
  646.     DSTMODE    DSTmode;
  647. {
  648.     static int DaysInMonth[12] = {
  649.     31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  650.     };
  651.     time_t    tod;
  652.     time_t    Julian;
  653.     int        i;
  654.  
  655.     if (Year < 0)
  656.     Year = -Year;
  657.     if (Year < 100)
  658.     Year += 1900;
  659.     DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0)
  660.             ? 29 : 28;
  661.     if (Year < EPOCH || Year > 1999
  662.      || Month < 1 || Month > 12
  663.      /* Lint fluff:  "conversion from long may lose accuracy" */
  664.      || Day < 1 || Day > DaysInMonth[(int)--Month])
  665.     return -1;
  666.  
  667.     for (Julian = Day - 1, i = 0; i < Month; i++)
  668.     Julian += DaysInMonth[i];
  669.     for (i = EPOCH; i < Year; i++)
  670.     Julian += 365 + (i % 4 == 0);
  671.     Julian *= SECSPERDAY;
  672.     Julian += yyTimezone * 60L;
  673.     if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
  674.     return -1;
  675.     Julian += tod;
  676.     if (DSTmode == DSTon
  677.      || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst))
  678.     Julian -= 60 * 60;
  679.     return Julian;
  680. }
  681.  
  682.  
  683. static time_t
  684. DSTcorrect(Start, Future)
  685.     time_t    Start;
  686.     time_t    Future;
  687. {
  688.     time_t    StartDay;
  689.     time_t    FutureDay;
  690.  
  691.     StartDay = (localtime(&Start)->tm_hour + 1) % 24;
  692.     FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
  693.     return (Future - Start) + (StartDay - FutureDay) * 60L * 60L;
  694. }
  695.  
  696.  
  697. static time_t
  698. RelativeDate(Start, DayOrdinal, DayNumber)
  699.     time_t    Start;
  700.     time_t    DayOrdinal;
  701.     time_t    DayNumber;
  702. {
  703.     struct tm    *tm;
  704.     time_t    now;
  705.  
  706.     now = Start;
  707.     tm = localtime(&now);
  708.     now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7);
  709.     now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
  710.     return DSTcorrect(Start, now);
  711. }
  712.  
  713.  
  714. static time_t
  715. RelativeMonth(Start, RelMonth)
  716.     time_t    Start;
  717.     time_t    RelMonth;
  718. {
  719.     struct tm    *tm;
  720.     time_t    Month;
  721.     time_t    Year;
  722.  
  723.     if (RelMonth == 0)
  724.     return 0;
  725.     tm = localtime(&Start);
  726.     Month = 12 * tm->tm_year + tm->tm_mon + RelMonth;
  727.     Year = Month / 12;
  728.     Month = Month % 12 + 1;
  729.     return DSTcorrect(Start,
  730.         Convert(Month, (time_t)tm->tm_mday, Year,
  731.         (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
  732.         MER24, DSTmaybe));
  733. }
  734.  
  735.  
  736. static int
  737. LookupWord(buff)
  738.     char        *buff;
  739. {
  740.     register char    *p;
  741.     register char    *q;
  742.     register const TABLE    *tp;
  743.     int            i;
  744.     int            abbrev;
  745.  
  746.     /* Make it lowercase. */
  747.     for (p = buff; *p; p++)
  748.     if (isupper(*p))
  749.         *p = tolower(*p);
  750.  
  751.     if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) {
  752.     yylval.Meridian = MERam;
  753.     return tMERIDIAN;
  754.     }
  755.     if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) {
  756.     yylval.Meridian = MERpm;
  757.     return tMERIDIAN;
  758.     }
  759.  
  760.     /* See if we have an abbreviation for a month. */
  761.     if (strlen(buff) == 3)
  762.     abbrev = 1;
  763.     else if (strlen(buff) == 4 && buff[3] == '.') {
  764.     abbrev = 1;
  765.     buff[3] = '\0';
  766.     }
  767.     else
  768.     abbrev = 0;
  769.  
  770.     for (tp = MonthDayTable; tp->name; tp++) {
  771.     if (abbrev) {
  772.         if (strncmp(buff, tp->name, 3) == 0) {
  773.         yylval.Number = tp->value;
  774.         return tp->type;
  775.         }
  776.     }
  777.     else if (strcmp(buff, tp->name) == 0) {
  778.         yylval.Number = tp->value;
  779.         return tp->type;
  780.     }
  781.     }
  782.  
  783.     for (tp = TimezoneTable; tp->name; tp++)
  784.     if (strcmp(buff, tp->name) == 0) {
  785.         yylval.Number = tp->value;
  786.         return tp->type;
  787.     }
  788.  
  789.     if (strcmp(buff, "dst") == 0) 
  790.     return tDST;
  791.  
  792.     for (tp = UnitsTable; tp->name; tp++)
  793.     if (strcmp(buff, tp->name) == 0) {
  794.         yylval.Number = tp->value;
  795.         return tp->type;
  796.     }
  797.  
  798.     /* Strip off any plural and try the units table again. */
  799.     i = strlen(buff) - 1;
  800.     if (buff[i] == 's') {
  801.     buff[i] = '\0';
  802.     for (tp = UnitsTable; tp->name; tp++)
  803.         if (strcmp(buff, tp->name) == 0) {
  804.         yylval.Number = tp->value;
  805.         return tp->type;
  806.         }
  807.     buff[i] = 's';        /* Put back for "this" in OtherTable. */
  808.     }
  809.  
  810.     for (tp = OtherTable; tp->name; tp++)
  811.     if (strcmp(buff, tp->name) == 0) {
  812.         yylval.Number = tp->value;
  813.         return tp->type;
  814.     }
  815.  
  816.     /* Military timezones. */
  817.     if (buff[1] == '\0' && isalpha(*buff)) {
  818.     for (tp = MilitaryTable; tp->name; tp++)
  819.         if (strcmp(buff, tp->name) == 0) {
  820.         yylval.Number = tp->value;
  821.         return tp->type;
  822.         }
  823.     }
  824.  
  825.     /* Drop out any periods and try the timezone table again. */
  826.     for (i = 0, p = q = buff; *q; q++)
  827.     if (*q != '.')
  828.         *p++ = *q;
  829.     else
  830.         i++;
  831.     *p = '\0';
  832.     if (i)
  833.     for (tp = TimezoneTable; tp->name; tp++)
  834.         if (strcmp(buff, tp->name) == 0) {
  835.         yylval.Number = tp->value;
  836.         return tp->type;
  837.         }
  838.  
  839.     return tID;
  840. }
  841.  
  842.  
  843. static int
  844. yylex()
  845. {
  846.     register char    c;
  847.     register char    *p;
  848.     char        buff[20];
  849.     int            Count;
  850.     int            sign;
  851.  
  852.     for ( ; ; ) {
  853.     while (isspace(*yyInput))
  854.         yyInput++;
  855.  
  856.     if (isdigit(c = *yyInput) || c == '-' || c == '+') {
  857.         if (c == '-' || c == '+') {
  858.         sign = c == '-' ? -1 : 1;
  859.         if (!isdigit(*++yyInput))
  860.             /* skip the '-' sign */
  861.             continue;
  862.         }
  863.         else
  864.         sign = 0;
  865.         for (yylval.Number = 0; isdigit(c = *yyInput++); )
  866.         yylval.Number = 10 * yylval.Number + c - '0';
  867.         yyInput--;
  868.         if (sign < 0)
  869.         yylval.Number = -yylval.Number;
  870.         return sign ? tSNUMBER : tUNUMBER;
  871.     }
  872.     if (isalpha(c)) {
  873.         for (p = buff; isalpha(c = *yyInput++) || c == '.'; )
  874.         if (p < &buff[sizeof buff - 1])
  875.             *p++ = c;
  876.         *p = '\0';
  877.         yyInput--;
  878.         return LookupWord(buff);
  879.     }
  880.     if (c != '(')
  881.         return *yyInput++;
  882.     Count = 0;
  883.     do {
  884.         c = *yyInput++;
  885.         if (c == '\0')
  886.         return c;
  887.         if (c == '(')
  888.         Count++;
  889.         else if (c == ')')
  890.         Count--;
  891.     } while (Count > 0);
  892.     }
  893. }
  894.  
  895. #define TM_YEAR_ORIGIN 1900
  896.  
  897. /* Yield A - B, measured in seconds.  */
  898. static long
  899. difftm (a, b)
  900.      struct tm *a, *b;
  901. {
  902.   int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
  903.   int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
  904.   int days = (
  905.           /* difference in day of year */
  906.           a->tm_yday - b->tm_yday
  907.           /* + intervening leap days */
  908.           +  ((ay >> 2) - (by >> 2))
  909.           -  (ay/100 - by/100)
  910.           +  ((ay/100 >> 2) - (by/100 >> 2))
  911.           /* + difference in years * 365 */
  912.           +  (long)(ay-by) * 365
  913.           );
  914.   return (60*(60*(24*days + (a->tm_hour - b->tm_hour))
  915.           + (a->tm_min - b->tm_min))
  916.       + (a->tm_sec - b->tm_sec));
  917. }
  918.  
  919. time_t
  920. get_date(p, now)
  921.     char        *p;
  922.     struct timeb    *now;
  923. {
  924.     struct tm        *tm, gmt;
  925.     struct timeb    ftz;
  926.     time_t        Start;
  927.     time_t        tod;
  928.     time_t nowtime;
  929.  
  930.     yyInput = p;
  931.     if (now == NULL) {
  932.         now = &ftz;
  933.     (void)time (&nowtime);
  934.  
  935.     if (! (tm = gmtime (&nowtime)))
  936.         return -1;
  937.     gmt = *tm;    /* Make a copy, in case localtime modifies *tm.  */
  938.  
  939.     if (! (tm = localtime (&nowtime)))
  940.         return -1;
  941.     
  942.     ftz.timezone = difftm (&gmt, tm) / 60;
  943.     if(tm->tm_isdst)
  944.         ftz.timezone += 60;
  945.     }
  946.     else
  947.     {
  948.     nowtime = now->time;
  949.     }
  950.  
  951.     tm = localtime(&nowtime);
  952.     yyYear = tm->tm_year;
  953.     yyMonth = tm->tm_mon + 1;
  954.     yyDay = tm->tm_mday;
  955.     yyTimezone = now->timezone;
  956.     yyDSTmode = DSTmaybe;
  957.     yyHour = 0;
  958.     yyMinutes = 0;
  959.     yySeconds = 0;
  960.     yyMeridian = MER24;
  961.     yyRelSeconds = 0;
  962.     yyRelMonth = 0;
  963.     yyHaveDate = 0;
  964.     yyHaveDay = 0;
  965.     yyHaveRel = 0;
  966.     yyHaveTime = 0;
  967.     yyHaveZone = 0;
  968.  
  969.     if (yyparse()
  970.      || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1)
  971.     return -1;
  972.  
  973.     if (yyHaveDate || yyHaveTime || yyHaveDay) {
  974.     Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds,
  975.             yyMeridian, yyDSTmode);
  976.     if (Start < 0)
  977.         return -1;
  978.     }
  979.     else {
  980.     Start = nowtime;
  981.     if (!yyHaveRel)
  982.         Start -= ((tm->tm_hour * 60L + tm->tm_min) * 60L) + tm->tm_sec;
  983.     }
  984.  
  985.     Start += yyRelSeconds;
  986.     Start += RelativeMonth(Start, yyRelMonth);
  987.  
  988.     if (yyHaveDay && !yyHaveDate) {
  989.     tod = RelativeDate(Start, yyDayOrdinal, yyDayNumber);
  990.     Start += tod;
  991.     }
  992.  
  993.     /* Have to do *something* with a legitimate -1 so it's distinguishable
  994.      * from the error return value.  (Alternately could set errno on error.) */
  995.     return Start == -1 ? 0 : Start;
  996. }
  997.  
  998.  
  999. #if    defined(TEST)
  1000.  
  1001. /* ARGSUSED */
  1002. int
  1003. main(ac, av)
  1004.     int        ac;
  1005.     char    *av[];
  1006. {
  1007.     char    buff[128];
  1008.     time_t    d;
  1009.  
  1010.     (void)printf("Enter date, or blank line to exit.\n\t> ");
  1011.     (void)fflush(stdout);
  1012.     while (gets(buff) && buff[0]) {
  1013.     d = get_date(buff, (struct timeb *)NULL);
  1014.     if (d == -1)
  1015.         (void)printf("Bad format - couldn't convert.\n");
  1016.     else
  1017.         (void)printf("%s", ctime(&d));
  1018.     (void)printf("\t> ");
  1019.     (void)fflush(stdout);
  1020.     }
  1021.     exit(0);
  1022.     /* NOTREACHED */
  1023. }
  1024. #endif    /* defined(TEST) */
  1025. #line 1026 "y.tab.c"
  1026. #define YYABORT goto yyabort
  1027. #define YYREJECT goto yyabort
  1028. #define YYACCEPT goto yyaccept
  1029. #define YYERROR goto yyerrlab
  1030. int
  1031. yyparse()
  1032. {
  1033.     register int yym, yyn, yystate;
  1034. #if YYDEBUG
  1035.     register char *yys;
  1036.     extern char *getenv();
  1037.  
  1038.     if (yys = getenv("YYDEBUG"))
  1039.     {
  1040.         yyn = *yys;
  1041.         if (yyn >= '0' && yyn <= '9')
  1042.             yydebug = yyn - '0';
  1043.     }
  1044. #endif
  1045.  
  1046.     yynerrs = 0;
  1047.     yyerrflag = 0;
  1048.     yychar = (-1);
  1049.  
  1050.     yyssp = yyss;
  1051.     yyvsp = yyvs;
  1052.     *yyssp = yystate = 0;
  1053.  
  1054. yyloop:
  1055.     if (yyn = yydefred[yystate]) goto yyreduce;
  1056.     if (yychar < 0)
  1057.     {
  1058.         if ((yychar = yylex()) < 0) yychar = 0;
  1059. #if YYDEBUG
  1060.         if (yydebug)
  1061.         {
  1062.             yys = 0;
  1063.             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  1064.             if (!yys) yys = "illegal-symbol";
  1065.             printf("%sdebug: state %d, reading %d (%s)\n",
  1066.                     YYPREFIX, yystate, yychar, yys);
  1067.         }
  1068. #endif
  1069.     }
  1070.     if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
  1071.             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
  1072.     {
  1073. #if YYDEBUG
  1074.         if (yydebug)
  1075.             printf("%sdebug: state %d, shifting to state %d\n",
  1076.                     YYPREFIX, yystate, yytable[yyn]);
  1077. #endif
  1078.         if (yyssp >= yyss + yystacksize - 1)
  1079.         {
  1080.             goto yyoverflow;
  1081.         }
  1082.         *++yyssp = yystate = yytable[yyn];
  1083.         *++yyvsp = yylval;
  1084.         yychar = (-1);
  1085.         if (yyerrflag > 0)  --yyerrflag;
  1086.         goto yyloop;
  1087.     }
  1088.     if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
  1089.             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
  1090.     {
  1091.         yyn = yytable[yyn];
  1092.         goto yyreduce;
  1093.     }
  1094.     if (yyerrflag) goto yyinrecovery;
  1095. #ifdef lint
  1096.     goto yynewerror;
  1097. #endif
  1098. yynewerror:
  1099.     yyerror("syntax error");
  1100. #ifdef lint
  1101.     goto yyerrlab;
  1102. #endif
  1103. yyerrlab:
  1104.     ++yynerrs;
  1105. yyinrecovery:
  1106.     if (yyerrflag < 3)
  1107.     {
  1108.         yyerrflag = 3;
  1109.         for (;;)
  1110.         {
  1111.             if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
  1112.                     yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
  1113.             {
  1114. #if YYDEBUG
  1115.                 if (yydebug)
  1116.                     printf("%sdebug: state %d, error recovery shifting\
  1117.  to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
  1118. #endif
  1119.                 if (yyssp >= yyss + yystacksize - 1)
  1120.                 {
  1121.                     goto yyoverflow;
  1122.                 }
  1123.                 *++yyssp = yystate = yytable[yyn];
  1124.                 *++yyvsp = yylval;
  1125.                 goto yyloop;
  1126.             }
  1127.             else
  1128.             {
  1129. #if YYDEBUG
  1130.                 if (yydebug)
  1131.                     printf("%sdebug: error recovery discarding state %d\n",
  1132.                             YYPREFIX, *yyssp);
  1133. #endif
  1134.                 if (yyssp <= yyss) goto yyabort;
  1135.                 --yyssp;
  1136.                 --yyvsp;
  1137.             }
  1138.         }
  1139.     }
  1140.     else
  1141.     {
  1142.         if (yychar == 0) goto yyabort;
  1143. #if YYDEBUG
  1144.         if (yydebug)
  1145.         {
  1146.             yys = 0;
  1147.             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  1148.             if (!yys) yys = "illegal-symbol";
  1149.             printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
  1150.                     YYPREFIX, yystate, yychar, yys);
  1151.         }
  1152. #endif
  1153.         yychar = (-1);
  1154.         goto yyloop;
  1155.     }
  1156. yyreduce:
  1157. #if YYDEBUG
  1158.     if (yydebug)
  1159.         printf("%sdebug: state %d, reducing by rule %d (%s)\n",
  1160.                 YYPREFIX, yystate, yyn, yyrule[yyn]);
  1161. #endif
  1162.     yym = yylen[yyn];
  1163.     yyval = yyvsp[1-yym];
  1164.     switch (yyn)
  1165.     {
  1166. case 3:
  1167. #line 202 "../../work/ccvs/lib/getdate.y"
  1168. {
  1169.         yyHaveTime++;
  1170.     }
  1171. break;
  1172. case 4:
  1173. #line 205 "../../work/ccvs/lib/getdate.y"
  1174. {
  1175.         yyHaveZone++;
  1176.     }
  1177. break;
  1178. case 5:
  1179. #line 208 "../../work/ccvs/lib/getdate.y"
  1180. {
  1181.         yyHaveDate++;
  1182.     }
  1183. break;
  1184. case 6:
  1185. #line 211 "../../work/ccvs/lib/getdate.y"
  1186. {
  1187.         yyHaveDay++;
  1188.     }
  1189. break;
  1190. case 7:
  1191. #line 214 "../../work/ccvs/lib/getdate.y"
  1192. {
  1193.         yyHaveRel++;
  1194.     }
  1195. break;
  1196. case 9:
  1197. #line 220 "../../work/ccvs/lib/getdate.y"
  1198. {
  1199.         yyHour = yyvsp[-1].Number;
  1200.         yyMinutes = 0;
  1201.         yySeconds = 0;
  1202.         yyMeridian = yyvsp[0].Meridian;
  1203.     }
  1204. break;
  1205. case 10:
  1206. #line 226 "../../work/ccvs/lib/getdate.y"
  1207. {
  1208.         yyHour = yyvsp[-3].Number;
  1209.         yyMinutes = yyvsp[-1].Number;
  1210.         yySeconds = 0;
  1211.         yyMeridian = yyvsp[0].Meridian;
  1212.     }
  1213. break;
  1214. case 11:
  1215. #line 232 "../../work/ccvs/lib/getdate.y"
  1216. {
  1217.         yyHour = yyvsp[-3].Number;
  1218.         yyMinutes = yyvsp[-1].Number;
  1219.         yyMeridian = MER24;
  1220.         yyDSTmode = DSToff;
  1221.         yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
  1222.     }
  1223. break;
  1224. case 12:
  1225. #line 239 "../../work/ccvs/lib/getdate.y"
  1226. {
  1227.         yyHour = yyvsp[-5].Number;
  1228.         yyMinutes = yyvsp[-3].Number;
  1229.         yySeconds = yyvsp[-1].Number;
  1230.         yyMeridian = yyvsp[0].Meridian;
  1231.     }
  1232. break;
  1233. case 13:
  1234. #line 245 "../../work/ccvs/lib/getdate.y"
  1235. {
  1236.         yyHour = yyvsp[-5].Number;
  1237.         yyMinutes = yyvsp[-3].Number;
  1238.         yySeconds = yyvsp[-1].Number;
  1239.         yyMeridian = MER24;
  1240.         yyDSTmode = DSToff;
  1241.         yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
  1242.     }
  1243. break;
  1244. case 14:
  1245. #line 255 "../../work/ccvs/lib/getdate.y"
  1246. {
  1247.         yyTimezone = yyvsp[0].Number;
  1248.         yyDSTmode = DSToff;
  1249.     }
  1250. break;
  1251. case 15:
  1252. #line 259 "../../work/ccvs/lib/getdate.y"
  1253. {
  1254.         yyTimezone = yyvsp[0].Number;
  1255.         yyDSTmode = DSTon;
  1256.     }
  1257. break;
  1258. case 16:
  1259. #line 264 "../../work/ccvs/lib/getdate.y"
  1260. {
  1261.         yyTimezone = yyvsp[-1].Number;
  1262.         yyDSTmode = DSTon;
  1263.     }
  1264. break;
  1265. case 17:
  1266. #line 270 "../../work/ccvs/lib/getdate.y"
  1267. {
  1268.         yyDayOrdinal = 1;
  1269.         yyDayNumber = yyvsp[0].Number;
  1270.     }
  1271. break;
  1272. case 18:
  1273. #line 274 "../../work/ccvs/lib/getdate.y"
  1274. {
  1275.         yyDayOrdinal = 1;
  1276.         yyDayNumber = yyvsp[-1].Number;
  1277.     }
  1278. break;
  1279. case 19:
  1280. #line 278 "../../work/ccvs/lib/getdate.y"
  1281. {
  1282.         yyDayOrdinal = yyvsp[-1].Number;
  1283.         yyDayNumber = yyvsp[0].Number;
  1284.     }
  1285. break;
  1286. case 20:
  1287. #line 284 "../../work/ccvs/lib/getdate.y"
  1288. {
  1289.         yyMonth = yyvsp[-2].Number;
  1290.         yyDay = yyvsp[0].Number;
  1291.     }
  1292. break;
  1293. case 21:
  1294. #line 288 "../../work/ccvs/lib/getdate.y"
  1295. {
  1296.         yyMonth = yyvsp[-4].Number;
  1297.         yyDay = yyvsp[-2].Number;
  1298.         yyYear = yyvsp[0].Number;
  1299.     }
  1300. break;
  1301. case 22:
  1302. #line 293 "../../work/ccvs/lib/getdate.y"
  1303. {
  1304.         /* ISO 8601 format.  yyyy-mm-dd.  */
  1305.         yyYear = yyvsp[-2].Number;
  1306.         yyMonth = -yyvsp[-1].Number;
  1307.         yyDay = -yyvsp[0].Number;
  1308.     }
  1309. break;
  1310. case 23:
  1311. #line 299 "../../work/ccvs/lib/getdate.y"
  1312. {
  1313.         /* e.g. 17-JUN-1992.  */
  1314.         yyDay = yyvsp[-2].Number;
  1315.         yyMonth = yyvsp[-1].Number;
  1316.         yyYear = -yyvsp[0].Number;
  1317.     }
  1318. break;
  1319. case 24:
  1320. #line 305 "../../work/ccvs/lib/getdate.y"
  1321. {
  1322.         yyMonth = yyvsp[-1].Number;
  1323.         yyDay = yyvsp[0].Number;
  1324.     }
  1325. break;
  1326. case 25:
  1327. #line 309 "../../work/ccvs/lib/getdate.y"
  1328. {
  1329.         yyMonth = yyvsp[-3].Number;
  1330.         yyDay = yyvsp[-2].Number;
  1331.         yyYear = yyvsp[0].Number;
  1332.     }
  1333. break;
  1334. case 26:
  1335. #line 314 "../../work/ccvs/lib/getdate.y"
  1336. {
  1337.         yyMonth = yyvsp[0].Number;
  1338.         yyDay = yyvsp[-1].Number;
  1339.     }
  1340. break;
  1341. case 27:
  1342. #line 318 "../../work/ccvs/lib/getdate.y"
  1343. {
  1344.         yyMonth = yyvsp[-1].Number;
  1345.         yyDay = yyvsp[-2].Number;
  1346.         yyYear = yyvsp[0].Number;
  1347.     }
  1348. break;
  1349. case 28:
  1350. #line 325 "../../work/ccvs/lib/getdate.y"
  1351. {
  1352.         yyRelSeconds = -yyRelSeconds;
  1353.         yyRelMonth = -yyRelMonth;
  1354.     }
  1355. break;
  1356. case 30:
  1357. #line 332 "../../work/ccvs/lib/getdate.y"
  1358. {
  1359.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
  1360.     }
  1361. break;
  1362. case 31:
  1363. #line 335 "../../work/ccvs/lib/getdate.y"
  1364. {
  1365.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
  1366.     }
  1367. break;
  1368. case 32:
  1369. #line 338 "../../work/ccvs/lib/getdate.y"
  1370. {
  1371.         yyRelSeconds += yyvsp[0].Number * 60L;
  1372.     }
  1373. break;
  1374. case 33:
  1375. #line 341 "../../work/ccvs/lib/getdate.y"
  1376. {
  1377.         yyRelSeconds += yyvsp[-1].Number;
  1378.     }
  1379. break;
  1380. case 34:
  1381. #line 344 "../../work/ccvs/lib/getdate.y"
  1382. {
  1383.         yyRelSeconds += yyvsp[-1].Number;
  1384.     }
  1385. break;
  1386. case 35:
  1387. #line 347 "../../work/ccvs/lib/getdate.y"
  1388. {
  1389.         yyRelSeconds++;
  1390.     }
  1391. break;
  1392. case 36:
  1393. #line 350 "../../work/ccvs/lib/getdate.y"
  1394. {
  1395.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  1396.     }
  1397. break;
  1398. case 37:
  1399. #line 353 "../../work/ccvs/lib/getdate.y"
  1400. {
  1401.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  1402.     }
  1403. break;
  1404. case 38:
  1405. #line 356 "../../work/ccvs/lib/getdate.y"
  1406. {
  1407.         yyRelMonth += yyvsp[0].Number;
  1408.     }
  1409. break;
  1410. case 39:
  1411. #line 361 "../../work/ccvs/lib/getdate.y"
  1412. {
  1413.         if (yyHaveTime && yyHaveDate && !yyHaveRel)
  1414.         yyYear = yyvsp[0].Number;
  1415.         else {
  1416.         if(yyvsp[0].Number>10000) {
  1417.             yyHaveDate++;
  1418.             yyDay= (yyvsp[0].Number)%100;
  1419.             yyMonth= (yyvsp[0].Number/100)%100;
  1420.             yyYear = yyvsp[0].Number/10000;
  1421.         }
  1422.         else {
  1423.             yyHaveTime++;
  1424.             if (yyvsp[0].Number < 100) {
  1425.             yyHour = yyvsp[0].Number;
  1426.             yyMinutes = 0;
  1427.             }
  1428.             else {
  1429.                 yyHour = yyvsp[0].Number / 100;
  1430.                 yyMinutes = yyvsp[0].Number % 100;
  1431.             }
  1432.             yySeconds = 0;
  1433.             yyMeridian = MER24;
  1434.             }
  1435.         }
  1436.     }
  1437. break;
  1438. case 40:
  1439. #line 388 "../../work/ccvs/lib/getdate.y"
  1440. {
  1441.         yyval.Meridian = MER24;
  1442.     }
  1443. break;
  1444. case 41:
  1445. #line 391 "../../work/ccvs/lib/getdate.y"
  1446. {
  1447.         yyval.Meridian = yyvsp[0].Meridian;
  1448.     }
  1449. break;
  1450. #line 1451 "y.tab.c"
  1451.     }
  1452.     yyssp -= yym;
  1453.     yystate = *yyssp;
  1454.     yyvsp -= yym;
  1455.     yym = yylhs[yyn];
  1456.     if (yystate == 0 && yym == 0)
  1457.     {
  1458. #if YYDEBUG
  1459.         if (yydebug)
  1460.             printf("%sdebug: after reduction, shifting from state 0 to\
  1461.  state %d\n", YYPREFIX, YYFINAL);
  1462. #endif
  1463.         yystate = YYFINAL;
  1464.         *++yyssp = YYFINAL;
  1465.         *++yyvsp = yyval;
  1466.         if (yychar < 0)
  1467.         {
  1468.             if ((yychar = yylex()) < 0) yychar = 0;
  1469. #if YYDEBUG
  1470.             if (yydebug)
  1471.             {
  1472.                 yys = 0;
  1473.                 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  1474.                 if (!yys) yys = "illegal-symbol";
  1475.                 printf("%sdebug: state %d, reading %d (%s)\n",
  1476.                         YYPREFIX, YYFINAL, yychar, yys);
  1477.             }
  1478. #endif
  1479.         }
  1480.         if (yychar == 0) goto yyaccept;
  1481.         goto yyloop;
  1482.     }
  1483.     if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
  1484.             yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
  1485.         yystate = yytable[yyn];
  1486.     else
  1487.         yystate = yydgoto[yym];
  1488. #if YYDEBUG
  1489.     if (yydebug)
  1490.         printf("%sdebug: after reduction, shifting from state %d \
  1491. to state %d\n", YYPREFIX, *yyssp, yystate);
  1492. #endif
  1493.     if (yyssp >= yyss + yystacksize - 1)
  1494.     {
  1495.         goto yyoverflow;
  1496.     }
  1497.     *++yyssp = yystate;
  1498.     *++yyvsp = yyval;
  1499.     goto yyloop;
  1500. yyoverflow:
  1501.     yyerror("yacc stack overflow");
  1502. yyabort:
  1503.     return (1);
  1504. yyaccept:
  1505.     return (0);
  1506. }
  1507.